我很近!默認情況下,按鈕處于啟用狀態。同樣,在檢查兩者時,都將啟用兩者,但是如果未選中,則僅禁用一個。
我想要它,以便在選中復選框時啟用兩個單選按鈕。未選中時,兩個單選按鈕都被禁用。
沒有Jquery,請
JS:
var sipch = document.querySelector("input[name=sip]");
sipch.addEventListener("change", function (event) {
if (event.currentTarget.checked) {
document.querySelector("input[name=protocol]").removeAttribute("disabled");
} else {
document.querySelector("input[name=protocol]").setAttribute("disabled", "disabled");
}
});
HTML:
<!DOCTYPE html>
<html lang="en">
<body>
<form id="myForm" onsubmit="goPVFive(event)" method="get">
<div id="pBFContainer" class="container">
<div id="bodyFOption1">
<input type="checkbox" name="sip" value="true">Would you like to include establishing the SIP session test?<p>
<input type="radio" class="testD" name="protocol" value="udp" disable/>UDP
<input type="radio" class="testD" name="protocol" value="tcp" disable/>TCP <label class="testD">(UDP is most Common)</label>
</div>
<div id="bodyFOption2">
<input type="checkbox" name="fWallInt" value="true">Would you include SIP ALG firewall interference test"
</div>
</div>
<input type="submit" id="subButton" value="Next..." />
</form>
</body>
<script type="text/javascript" src="evalportalp1.js"></script>
</html>
uj5u.com熱心網友回復:
你需要使用 querySelectorAll 然后遍歷結果,禁用/啟用它們中的每一個:
if (event.currentTarget.checked) {
document.querySelectorAll('input[name=protocol]')
.forEach((elem) => elem.removeAttribute('disabled'));
} else {
document.querySelectorAll('input[name=protocol]')
.forEach((elem) => elem.setAttribute('disabled', 'disabled'));
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/496341.html
標籤:javascript html 形式 复选框 单选按钮
上一篇:3個復選框以不同方式更新引數
