admin管理员组文章数量:1392003
What wrong with the my code. When I click on the checkbox, nothing happen
$(document).ready(function(){
$('input:checkbox[name=drawingNo]').click(function(){alert('I am here');});
});
...
<body>
<form>
<input type="checkbox" name="drawingNo" value="1"> 1 <br>
<input type="checkbox" name="drawingNo" value="2"> 2 <br>
<input type="checkbox" name="drawingNo" value="3"> 3 <br>
<input type="checkbox" name="drawingNo" value="4"> 4 <br>
</form>
</body>
EDIT: The above code worked fine. What happen to me is that, the tag <input type="checkbox">
are generated by some other script, so when document.ready() fire up, it cant register click event to checkbox, since these checkbox are not really there yet. So to fixed it: change .click()
into .live('click', function(){...})
What wrong with the my code. When I click on the checkbox, nothing happen
$(document).ready(function(){
$('input:checkbox[name=drawingNo]').click(function(){alert('I am here');});
});
...
<body>
<form>
<input type="checkbox" name="drawingNo" value="1"> 1 <br>
<input type="checkbox" name="drawingNo" value="2"> 2 <br>
<input type="checkbox" name="drawingNo" value="3"> 3 <br>
<input type="checkbox" name="drawingNo" value="4"> 4 <br>
</form>
</body>
EDIT: The above code worked fine. What happen to me is that, the tag <input type="checkbox">
are generated by some other script, so when document.ready() fire up, it cant register click event to checkbox, since these checkbox are not really there yet. So to fixed it: change .click()
into .live('click', function(){...})
4 Answers
Reset to default 4Your selector is wrong..
The below is the best format
$(document).ready(function(){
$("input[name='drawingNo']").live('click', function(){
alert('I am here');
});
});
It works fine for me in IE, FF and Chrome.
Use $.fn.live ...
$('input:checkbox[name=drawingNo]').live('click',function(){
alert('I am here');
});
try removing ':checkbox' so that it looks like:
$('input[name=drawingNo]').click(function(){alert('I am here');});
any better?
本文标签: javascriptDetect checkbox has been click with JQueryStack Overflow
版权声明:本文标题:javascript - Detect checkbox has been click with JQuery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744759210a2623650.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论