admin管理员组文章数量:1323348
I am new to jQuery and cannot get a selector to work using the id of the element. The code below works:
$(function() {
/* $("#ShowBox").onclick = ShowAccessible; */
document.getElementById("ShowBox").onclick = ShowAccessible;
/* $(".searchcheck").click = ShowAccessible; */
});
function ShowAccessible() {
$("tr.hide").fadeOut();
}
However, neither of the two mented out lines work i.e. they do not apply the click event to a checkbox named "ShowBox" with a class of "searchcheck". Why is this?
I am new to jQuery and cannot get a selector to work using the id of the element. The code below works:
$(function() {
/* $("#ShowBox").onclick = ShowAccessible; */
document.getElementById("ShowBox").onclick = ShowAccessible;
/* $(".searchcheck").click = ShowAccessible; */
});
function ShowAccessible() {
$("tr.hide").fadeOut();
}
However, neither of the two mented out lines work i.e. they do not apply the click event to a checkbox named "ShowBox" with a class of "searchcheck". Why is this?
Share Improve this question edited May 22, 2009 at 12:52 Tomalak 338k68 gold badges546 silver badges635 bronze badges asked May 22, 2009 at 11:35 yubenyuben 6931 gold badge9 silver badges23 bronze badges3 Answers
Reset to default 8there is no onclick property for a jQuery object; when you use $([selector])
, a jQuery object is returned, not an element.
Use either
.click(function () { ...}); // can be an anonymous function or named function
or
.bind('click', function() { ... }); // can be an anonymous function or named function
like so
$("#ShowBox").click(ShowAccessible);
$("#ShowBox").bind('click', ShowAccessible);
JQuery uses functions rather than properties to set the handlers.
$("#ShowBox").click(ShowAccessible);
if you really had to do it with an assignment , i think
$("#ShowBox")[0].onclick = ShowAccessible;
would work.
本文标签: javascriptHow does jQuery handle the click eventStack Overflow
版权声明:本文标题:javascript - How does jQuery handle the click event? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742132283a2422217.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论