gpt4 book ai didi

javascript - jQuery 复选框错误

转载 作者:行者123 更新时间:2023-11-29 16:12:53 25 4
gpt4 key购买 nike

我正在进行表单验证,如果所有者复选框未选中但它不起作用,我将其他复选框的属性设置为禁用。
这是我的 html 代码:

<!DOCTYPE html>
<html>
<head>
<title>jQuery</title>

<script src="script.js"></script>
<script src="min.js"></script>

</head>
<body>

Owner:<input type="checkbox" id="owner">
<hr>
<div id="check">
bicycle:<input type="checkbox" id="bicycle"><br>
bike:<input type="checkbox" id="bike"><br>
car:<input type="checkbox" id="car">
</div>

<script>


</script>


</body>
</html>

其中 min.js 是 jQuery 安装文件,
这是 script.js :

$(document).ready(function(){

var $checkbox = $("#check").find("input[type=checkbox]");
$checkbox.prop('disabled', true);

$("#owner").click(function(){
var $ownercheck = $(this);

if ($ownercheck.prop('checked') === true) {
$checkbox.prop('disabled', false);
}
else
{
$checkbox.prop('disabled', true);
}

});

});

最佳答案

你必须把 min.js 放在 script.js 之上,
您的 html 代码将如下所示:

<!DOCTYPE html>
<html>
<head>
<title>jQuery</title>

<script src="min.js"></script>
<script src="script.js"></script>

</head>
<body>

Owner:<input type="checkbox" id="owner">
<hr>
<div id="check">
bicycle:<input type="checkbox" id="bicycle"><br>
bike:<input type="checkbox" id="bike"><br>
car:<input type="checkbox" id="car">
</div>

</body>
</html>

关于javascript - jQuery 复选框错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23402832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com