我必须首先禁用输入,然后单击链接以启用它们.
这是我到目前为止所尝试的,但它不起作用:
HTML:
<input type="text" disabled="disabled" class="inputDisabled" value="">
Run Code Online (Sandbox Code Playgroud)
jQuery的:
$("#edit").click(function(event){
event.preventDefault();
$('.inputDisabled').removeAttr("disabled")
});
Run Code Online (Sandbox Code Playgroud)
这显示了我true,false但输入没有任何变化:
$("#edit").click(function(event){
alert('');
event.preventDefault();
alert($('.inputDisabled').attr('disabled'));
$('.inputDisabled').removeAttr("disabled");
alert($('.inputDisabled').attr('disabled'));
});
Run Code Online (Sandbox Code Playgroud) 好的,在这里遇到一些麻烦,想在选择收音机时禁用一些选项.选择ABC时,禁用1,2和3选项等...
$("input:radio[@name='abc123']").click(function() {
if($(this).val() == 'abc') {
// Disable
$("'theOptions' option[value='1']").attr("disabled","disabled");
$("'theOptions' option[value='2']").attr("disabled","disabled");
$("'theOptions' option[value='3']").attr("disabled","disabled");
} else {
// Disbale abc's
}
});
ABC: <input type="radio" name="abc123" id="abc"/>
123: <input type="radio" name="abc123" id="123"/>
<select id="theOptions">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
Run Code Online (Sandbox Code Playgroud)
不工作任何想法?
更新:
好的我启用/禁用工作但是出现了一个新问题.我的选择框的禁用选项仅适用于FF和IE8.我测试了IE6,而且残疾人无法正常工作.我试图使用hide()和show()也没有运气.基本上我需要隐藏/禁用/删除选项(适用于所有浏览器),并且如果选择了其他无线电选项则能够将它们添加回来,反之亦然.
结论:
感谢所有解决方案,他们中的大多数都回答了我原来的问题.对所有人提出了很多建议:)
我有一个辅助选择奴隶到主要选择(选择一个商店,然后选择一个部门 - 相同的选择一个国家,然后选择一个州).
无论我撕掉多少其他代码,我绝对无法使用select2('enable',false)和('data',null)方法.
<select id="stores">
<option value="foo">foo</option>
</select>
<select id="depts">
<option value="bar">bar</option>
</select>
// ...some logic that selects a store, then fetches that store's depts ...
$('#depts').select2('enable',false);// does not disable control
$('#depts').select2('data',null); // does not clear control
Run Code Online (Sandbox Code Playgroud)
所以我被迫这样做:
$('select#depts').empty(); // clears HTML element
$('#depts').select2(); // re-enhances select w/ select2
$('#depts').select2('disable',true); // disables
Run Code Online (Sandbox Code Playgroud)
它在jsfiddle中表现得很好,所以我甚至无法发布示例并请求帮助.我只是......难过.
我需要从表中显示一些预先存在的数据,但需要禁用它们以防止用户编辑它们.所以我禁用了他们
$form -> getElement("elementname") -> setAttrib("disable", true);
当我提交表单时,我发现表单元素根本没有提交,只是因为它被禁用了.当我测试删除禁用选项时,我确认了这一点.
怎么了?难道我做错了什么?怎么解决这个?