所以我想要的是當我點擊豪華我想要所有的選項進行檢查,所以霧燈皮革和DVD,但它不工作..我不知道我的jQuery有什麼問題:/請幫忙還當我點擊一個選項,讓我們說,我想霧燈,機器會自動檢查自定義一個輸入JavaScript代碼不工作
<!doctype html>
<html>
<head>
<title>A basic form</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js">
</script>
<style type="text/css">
.form-field {
clear: both;
padding: 10px;
width: 350px;
}
.form-field label {
float: left;
width: 150px;
text-align: right;
}
.form-field input {
float: right;
width: 150px;
text-align: left;
}
#submit {
text-align: center;
}
</style>
</head>
<body>
<h1>a basic form</h1>
<hr>
<form action="#">
<fieldset>
<legend>
Car trim and package information
</legend>
<div class="form-field">
<div>Package:</div>
<input id="plain" type="radio" name="trim" value="plain">
<label for="plain">Plain</label>
<input id="deluxe" type="radio" name="trim" value="custom">
<label for="deluxe">Deluxe</label>
<input id="custom" type="radio" name="trim" value="custom">
<label for="custom">Custom</label>
</div>
<div class="form-field">
<div>Extra Options:</div>
<div>
<input type="checkbox" id="foglights" name="option">
<label for="foglights">Fog Lights</label>
</div>
<div>
<input type="checkbox" id="leather" name="option" value="leather">
<label for="leather">Leather</label>
</div>
<input type="checkbox" id="dvd" name="option" value="dvd">
<label for="dvd">DVD</label>
</div>
<div class="form-field">
<input id="submit" type="submit" name="submit" value="Send Form">
</div>
</fieldset>
</form>
<script type="text/javascript">
$(documet).ready(function() {
$("input[name="trim"]").click(function(event) {
if ($(this).val() == "deluxe") {
$("input[name="option"]").attr("xxxxxxxxxxChecked", true);
}else if ($(this).val() == "plain") {
$("input[name="option"]").attr("Checked", false);
}
});
$("input[name="option"]").click(function(event) {
$("#custom").attr("Checked", "Checked")
}
});
</script>
</body>
第一次使用'document',而不是'documet' –
_「我不知道什麼是錯我的jQuery」 _ - 檢查你的瀏覽器控制檯,按F12。您還需要編寫像這樣的屬性選擇器:'$(「input [name ='option']」)''。 – Xufox