有没有人有任何想法为什么这段代码似乎不工作? 我在做什么错?jquery复选框attr更改似乎不工作
使用JQuery 1.5.1。
JS代码:
$('#search_filters #discipline a').click(function(){
var checkbox = $(this).next(':checkbox');
if (checkbox.attr('checked')) {
checkbox.attr("checked", true);
} else {
checkbox.attr("checked", false);
}
$(this).children('img').toggleClass("active");
return false;
});
HTML:
<li>
<a href="#">
<img class="inactive" alt="Football" src="/images/disciplines/e9bc7681813110c/thumb.png">
</a>
<input type="checkbox" name="search_discipline[7]" value="1" class="search_discipline">
</li>
并非如此。要么会工作。退房:http://jsfiddle.net/nbjV5/。事实上,如果你警告($(“#test1”)。attr(“checked”));'你会得到'真'或'假' – 2011-03-31 10:36:51