我需要一些幫助,因爲我卡住了。Bootstrap/Javascript - 如果選中了一個複選框,否則全部取消選擇
所以基本上我有這樣的:
$(function() {
$('.turn_on').on("click", function() {
var checked = $(this).is(':checked');
var $otherChecks = $('.check_1, .check_2');
$otherChecks.removeAttr('disabled', checked);
});
});
$('.turn_on').change(function() {
if(this.checked){
var $otherChecks = $('.check_1, .check_2');
$otherChecks.removeAttr('disabled', checked);
}else{
var checked = $(this).is(':checked');
var $otherChecks1 = $('.check_1, .check_2');
$otherChecks1.removeAttr('disabled', checked);
}
});
<form method="post">
<label class="checkbox"><input type="checkbox" name="turn_on" value="turn_on" class="turn_on">Turn on</label>
<br>
<label class="checkbox"><input type="checkbox" name="check_1" value="check_1" class="check_1" disabled>Option 1</label>
<label class="checkbox"><input type="checkbox" name="check_2" value="check_2" class="check_2" disabled>Option 2</label>
<button type="submit" class="btn btn-primary" name="submit">Save</button>
</form>
第一個腳本工作正常,但與「變」的劇本不起作用。 基本上,當用戶選中「turn_on」框時,它會「禁用」所有其他複選框。
我也擁有所有的div和腳本。 這只是代碼不能改變。
php部分在哪裏? – Epodax
什麼是PHP的一部分? @Epodax –
您用php標記了您的問題 – Epodax