jQuery的按鈕來添加/刪除禁用屬性:無法根據複選框選中屬性
<script type="text/javascript">
function enableDisableButton() {
var isChecked = ($('input[name=ignore-checkbox]').is(':checked'));
if (isChecked == true) {
$("button[name=set-up-account]").removeAttr("disabled");
}
else {
$("button[name=set-up-account]").attr("disabled", "disabled");
}
}
$('#mobilePage').live('pageinit', function (event) { //document ready for jquery mobile
enableDisableButton();
$('#ignore-checkbox').bind("change", function() {
enableDisableButton();
});
});
</script>
HTML:
@using (Html.BeginForm("Account", "SetUpAccount", FormMethod.Post, new { @id = "account-set-up", @data_ajax = "false" }))
{
<div class="ui-grid-a field">
<div class="ui-block-a" style="width:140px;">
<label for="ignore-checkbox">Ignore</label>
<input type="checkbox" name="ignore-checkbox" id="ignore-checkbox"/>
</div>
</div>
<div style="width:100%;float:left;">
<button type="submit" name="set-up-account" id="set-up-account" data-inline="true" data-mini="true">Set Up Account</button>
</div>
}
我想啓用/基於複選框禁用Set Up Account
按鈕選中屬性。如果複選框被選中,則啓用按鈕,否則禁用。在頁面加載我正在禁用按鈕
我現在面臨的問題是,
在頁面加載,它禁用按鈕,但基於複選框的更改事件它不是添加/刪除disabled屬性,我檢查螢火蟲,它根據檢查和未檢查的值正確進入循環。
注意:我正在使用Jquery mobile 1.2和jquery 1.7。另外在發佈之前,我在谷歌搜索,有很多張貼下啓用和禁用基於複選框選中的值的按鈕。但沒有解決我的問題。
有什麼問題?請幫我
謝謝...
您的代碼正常工作,請參閱此處演示:http://jsfiddle.net/dwzGf/2/':)'點擊複選框,您將看到啓用和禁用按鈕 –
但是在我的頁面中,關於檢查複選框的禁用屬性,其可能是因爲jquery mobile? – Subha
試試這個 - 小改動:http:// jsfiddle。net/26n4M/1 /而不是'(isChecked == true)'只需要執行'(isChecked)',它應該在JQ M'中運行:'' –