我有一個表單,其中包含多個複選框,如果選中某個方框,我想禁用表單。我將在我的網站上多次出現這種情況,我想知道是否有比我目前嘗試的更好的方式(哪個不能正常工作)。如果我想多次使用這個相同的禁用函數,我應該創建一個類'disable'嗎?謝謝!如何根據複選框選擇禁用表單
JS
$(document).ready(function()
{
$('#disabler_0').click(function()
{
$('[name*=form1]').attr('disabled', 'disabled')
});
});
HTML
<form id="form1" name="form1" method="post" action="">
<p>
<label>
<input type="checkbox" name="disabler" value="one" id="disabler_0" />
one</label>
<br />
<label>
<input type="checkbox" name="disabler" value="two" id="disabler_1" />
two</label>
<br />
<label>
<input type="checkbox" name="disabler" value="three" id="disabler_2" />
three</label>
<br />
<label>
<input type="checkbox" name="disabler" value="four" id="disabler_3" />
four</label>
<br />
<label>
<input type="checkbox" name="disabler" value="five" id="disabler_4" />
five</label>
<br />
</p>
</form>
當你說禁用表單將如何顯示給用戶?你想要一個覆蓋?只需禁用所有的複選框? – 2011-05-12 13:57:16
禁用所有複選框。 – dzilla 2011-05-12 13:59:12