[英]Disabled element through the JS code - not working
我有兩個單選按鈕,單擊其中一個,我將允許下面的輸入,單擊另一個,我將允許第二個輸入。
這是我的HTML:
<fieldset data-role="controlgroup">
<input onclick="ChangeChoise(1);" type="radio" name="radio-choice" id="radio-choice-1" value="choice-1" checked="checked" />
<input id="Input1"/>
<input onclick="ChangeChoise(2);" type="radio" name="radio-choice" id="radio-choice-2" value="choice-2" />
<input disabled="disabled" id="Input2"/>
</fieldset>
首先,第二個輸入未啟用,通過單擊輸入運行以下功能:
var ChoseDiv = 1;
function ChangeChoise(NumChoise) {
if (ChoseDiv == NumChoise)
return;
else
if (NumChoise == 1) {
$('#MyInput2').attr('disabled', 'disabled');
$('#MyInput1').attr('disabled', '');
}
else {
$('#MyInput1').attr('disabled', 'disabled');
$('#MyInput2').attr('disabled', '');
}
ChoseDiv = NumChoise;
}
這沒用
我也這樣嘗試: $('#MyInput2').removeAttr('disabled');
它沒有用..
我想念什么?
jQuery Mobile具有啟用/禁用功能:
$('#Input1').textinput('disable');
$('#Input2').textinput('enable');
這是一個工作示例: http : //jsfiddle.net/Gajotres/5N3vL/
這是官方文檔: http : //jquerymobile.com/demos/1.2.0/docs/forms/search/methods.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.