我希望能夠取消選中複選框,如果我已經使用jQuery選擇了我的下拉菜單。我覺得我可能幾乎在那裏,但不知道爲什麼它不工作。例如,我點擊MR,然後我改爲醫生 - MR選擇。設置一個複選框,當點擊下拉框時取消選中
<script>
$('.multiple-choice').click(function(){
$('input').prop('checked', false);
});
</script>
<fieldset class="title-box">
<span><input type="radio" name="title" value="Mr" onclick="titlehandler(this)" id="titlemr" th:field="*{title}" /> <label for="titlemr" id="mr-label">Mr</label></span>
<span><input type="radio" name="title" value="Mrs" onclick="titlehandler(this)" id="titlemrs" th:field="*{title}" /> <label for="titlemrs" id="mrs-label">Mrs</label></span>
<span><input type="radio" name="title" value="Miss" onclick="titlehandler(this)" id="titlemiss" th:field="*{title}" /> <label for="titlemiss" id="miss-label">Miss</label></span>
<span><input type="radio" name="title" value="Ms" onclick="titlehandler(this)" id="titlems" th:field="*{title}" /> <label for="titlems" id="ms-label">Ms</label></span>
<span><label for="dropdown">Other</label>
<select name="dropdown" id="dropdown" class="multiple-choice">
<option value="Dr" name="othertitle1" id="othertitle1">Dr</option>
<option value="Rev">Rev</option>
<option value="Sir">Sir</option>
<option value="Sist">Sist</option></select>
</fieldset>
<script>
\t $('.multiple-choice').click(function(){
$('input').prop('checked', false);
});
</script>
<fieldset class="title-box">
\t \t \t \t \t \t \t
\t <span><input type="radio" name="title" value="Mr" onclick="titlehandler(this)" id="titlemr" th:field="*{title}" /> <label for="titlemr" id="mr-label">Mr</label></span>
\t <span><input type="radio" name="title" value="Mrs" onclick="titlehandler(this)" id="titlemrs" th:field="*{title}" /> <label for="titlemrs" id="mrs-label">Mrs</label></span>
\t <span><input type="radio" name="title" value="Miss" onclick="titlehandler(this)" id="titlemiss" th:field="*{title}" /> <label for="titlemiss" id="miss-label">Miss</label></span>
\t <span><input type="radio" name="title" value="Ms" onclick="titlehandler(this)" id="titlems" th:field="*{title}" /> <label for="titlems" id="ms-label">Ms</label></span>
\t \t <span><label for="dropdown">Other</label>
\t \t <select name="dropdown" id="dropdown" class="multiple-choice">
<option value="Dr" name="othertitle1" id="othertitle1">Dr</option>
<option value="Rev">Rev</option>
<option value="Sir">Sir</option>
<option value="Sist">Sist</option></select>
</fieldset>
將您的JS代碼_after_ HTML標記。目前它在HTML行加載之前執行。 –
或者將它包裝在'$(document).ready'中。 – briosheje