这段简单的代码在 jquery 1.8.3 中完美运行 然而 > jquery 1.8.3 它停止工作。 我做错了什么?
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#button').click(function(){
if($("#stc").is(':checked'))
{
$("#stc").attr('checked', false);
//do some code
}
else
{
$("#stc").attr('checked', true);
//do some other code
//so no toggle() I believe
}
});
});
</script>
</head>
<body>
<button id="button">(de)select</button>
<input type="checkbox" id="stc">
</body>
</html>
自己试试 1.8.3:
最佳答案
使用这个 prop()
if($("#stc").is(':checked')) {
$(this).prop('checked', false);
//do some code
} else {
$(this).prop('checked', true);
}
关于带有复选框的 jQuery 版本控制错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28872298/