我如何使用「id」僅應用禁用/啓用按鈕,如果只有第二個按鈕被點擊複選框,因爲我需要它來打開和關閉取決於if點擊複選框。凡爲第一個按鈕將永遠是第二提交按鈕的只適用於一個輸入按鈕
http://jsfiddle.net/BPhZe/2122/
<h1>Button should be enabled if at least one checkbox is checked</h1>
<form>
<div>
<input type="checkbox" name="option-1" id="option-1"> <label for="option-1">Option 1</label>
</div>
<div>
<input type="checkbox" name="option-2" id="option-2"> <label for="option-2">Option 2</label>
</div>
<div>
<input type="submit" id="sub1" value="Do thing">
</div>
<div>
<input type="checkbox" name="here" id="option-12"> <label for="option-2">Option 3</label>
</div>
<div>
<input type="checkbox" name="now" id="option-22"> <label for="option-2">Option 4</label>
</div>
<div>
<input type="submit" id="sub2" value="Do thing" disabled="true">
</div>
</form>
var checkboxes = $("input[type='checkbox']"),
submitButt = $("input[type='submit']");
checkboxes.click(function() {
submitButt.attr("disabled", !checkboxes.is(":checked"));
});
感謝您的回答! – John 2015-03-31 09:52:47
@John不客氣:)請接受我的asnwer :) – 2015-03-31 09:53:31