2013-09-23 123 views
2

在頁面加載期間,我有一個複選框被禁用。按下按鈕時,我希望啓用它。它適用於我的桌面版本,但不適用於我的jQuery Mobile版本。如果我做的相反(啓用加載和使用按鈕禁用,它工作得很好)。下面是代碼:JQuery複選框啓用/禁用使用Jquery Mobile

HTML:

<div> 
    @Html.CheckBoxFor(model => model.Terms, new { id = "terms", disabled = "disabled"}) 
</div> 

<div> 
<input type="button" id="blah" name="blah" data-inline="true" value="blah" /> 
</div> 

的jQuery:

<script language="javascript" type="text/javascript"> 
$().ready(function() { 
    $("#blah").click(function() {    
     $('#terms').removeAttr('disabled'); 
    }); 
}); 
</script> 

任何幫助將不勝感激!

謝謝!

+0

按鈕或複選框? – Omar

+0

我想使用按鈕啓用複選框。 – Loganj99

回答

0

首先,you shouldn't use.ready()在jQuery Mobile中。始終使用jQuery Mobile events

對於您的問題,您需要使用.prop('disabled, false),然後調用增強方法.checkboxradio('refresh')重新設置複選框的樣式。

Demo

$('#blah').on('click', function() { 
    $('#foo').prop('disabled', false).checkboxradio('refresh'); 
}); 
+1

像魅力一樣工作,謝謝! – Loganj99