【发布时间】:2013-03-28 22:27:03
【问题描述】:
我试图将click 事件添加到我项目中的 div Id 中,但它引发了错误。我不知道为什么。有人可以看看代码吗?
HTML:
<div id="container">
<div id="header1">
<input type="button" value="Search and Highlight!!" style="position: absolute; right: 100px; top: 10px;" />
</div>
...
jQuery:
var searchAttachPoint = document.querySelector('.header1');
$('#header1').live("click", function () {
myNameSpace.searchPrompt("Key the text and press Ok", false)
}); // The error is thrown in this line
var attachpoint = document.querySelector('.buttonAttachPoint');
$(document).on('load', myNameSpace.LoadAllBooks("ajax/metadata.json", this.attachpoint));
【问题讨论】:
-
您使用的是什么版本的 Jquery?
live在 Jquery 1.9 中被删除,api.jquery.com/live -
那些
querySelector是干什么用的? -
@Bergi 我以前从未见过这些......在快速谷歌之后,它似乎是 jQuery/sizzle 用来选择元素的“本机”JS 方法:developer.mozilla.org/en-US/docs/DOM/Document.querySelector
-
@jammypeach:我知道他们在做什么,我在问 OP 他试图用它们做什么(因为他似乎做错了)。
-
@Bergi 原谅我的假设 :)
标签: javascript html jquery