我在我的网站上疯狂地测试了一些 jquery 脚本,但没有任何效果,而它可以在 Fiddles 上工作......
这就是我的:
然后我有一个如下的脚本,但我无法让它工作!!!
<script type="text/javascript">
$(":checkbox").bind("click", function(event) {
if ($(this).is(':checked')) {
$(".itemBox:not(#" + $(this).val() + ")").hide();
$(".itemBox[id='" + $(this).val() + "']").show();
} else {
$(".itemBox").show();
}
});
</script>
最佳答案
您必须等待文档加载,然后才能将事件绑定(bind)到它。
jQuery 提供了一种简单的方法来做到这一点,作者:calling the ready
method on the document ,并将所有代码放入该函数中:
jQuery(document).ready(function($) {
// All of your code should go in this function
});
关于javascript - Jquery头标签问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11785289/