如果用户改变选择框我要禁用的形式内的所有字段,而不触发选择框和一个特定的ID为输入场= XYZ的选项。禁用除1个字段中的所有改变formfields后一个选择框
我如何在快速和最简单的方式做到这一点。
“#newsite_IS_HELPER”是选择框的id
$('#newsite_IS_HELPER').change(function(){
alert('What i have to do?');
});
如果用户改变选择框我要禁用的形式内的所有字段,而不触发选择框和一个特定的ID为输入场= XYZ的选项。禁用除1个字段中的所有改变formfields后一个选择框
我如何在快速和最简单的方式做到这一点。
“#newsite_IS_HELPER”是选择框的id
$('#newsite_IS_HELPER').change(function(){
alert('What i have to do?');
});
你可以通过选择所有输入单元的形式下,并排除你不想选择即this
元素是什么(其中一个被触发禁用动作即你的情况select
)中并用#xyz
输入元件。
$('#your_form_id :input:not(#xyz):not(#newsite_IS_HELPER)').prop("disabled", true);
$('#newsite_IS_HELPER').change(function(){
var this_val = $(this).val();
var disable_all = false;
if(this_val != "1"){
disable_all = true;
}
$('#your_form_id :input:not(#xyz):not(#newsite_IS_HELPER)').prop("disabled", disable_all);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form id="your_form_id">
<input id="xyz">
<input><input><input><input><input>
<select id="newsite_IS_HELPER">
<option value="1">enable all</option><option value="2">disable all</option><option value="3">disable all again</option>
</select>
</form>
我怎么办,
$ ('#newsite_IS_HELPER').change(function(){
$("input").attr("disabled", "disabled");
$(this).attr("disabled",false);
$("#xyz").attr("disabled",false);
});
或者,否则,你可代替attr的使用道具,像波纹管我的代码,
你是什么意思*没有t 。他触发选择框* –
的选择框至极改变不应该被禁用(和一个斯佩恰输入字段太) - 香港专业教育学院编辑上面的代码。 – newbieRB