下面的腳本將在選中欄位時將該disabled屬性添加到其他輸入欄位#alt_hp,但是當我取消選中該欄位時,禁用的屬性不會被洗掉。我不是那么精通 javascript,并試圖理解該站點上的其他解決方案。
<script>
$("#alt_hp").change(function() {
if ($("input[type=checkbox]").is( ":checked" )) {
$("#new_displacement").val('')
$("input#induction, input#heads, input#camshaft, input#turbo, input#boost, input#inc_displacement").prop("checked", false).prop("disabled", true)
} else {
$("input#induction, input#heads, input#camshaft, input#turbo, input#boost, input#inc_displacement").prop("disabled", false)
}
});
</script>
uj5u.com熱心網友回復:
只需更改以下行
if ($("input[type=checkbox]").is( ":checked" )) {
對此
if ($(this).is(":checked")) {
您現有的代碼將始終參考any/all整個 html 中的復選框。this指當前的復選框/元素。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/485379.html
標籤:javascript jQuery
上一篇:在Jquery中模擬“退格”
