jQuery:禁用除当前元素之外的类
我有一个表,其中有几个字段充当过滤器。 所有字段都具有相同的类,默认情况下为空 是否有一种方法,我一次只能允许其中一个字段处于活动状态,同时禁用所有其他字段? 我想实现的是,您一次只能填写一个字段,即如果您填写一个字段,则其他字段将被禁用,当您再次清空此字段时,其他字段将被重新激活 我的想法是在输入数据时添加一个临时类,但我无法让它工作 我的字段都是这样的:jQuery:禁用除当前元素之外的类,jquery,disabled-input,input-field,Jquery,Disabled Input,Input Field,我有一个表,其中有几个字段充当过滤器。 所有字段都具有相同的类,默认情况下为空 是否有一种方法,我一次只能允许其中一个字段处于活动状态,同时禁用所有其他字段? 我想实现的是,您一次只能填写一个字段,即如果您填写一个字段,则其他字段将被禁用,当您再次清空此字段时,其他字段将被重新激活 我的想法是在输入数据时添加一个临时类,但我无法让它工作 我的字段都是这样的: <input type="text" class="inputFilter" id="input1" name="input1" v
<input type="text" class="inputFilter" id="input1" name="input1" value="" />
非常感谢您的帮助,蒂姆。试试看
jQuery(function(){
var $inputs = $('.inputFilter').on('input blur', function () {
var value = $.trim(this.value);
$inputs.not(this).prop('disabled', value.length != 0);
})
})
演示:试试看
jQuery(function(){
var $inputs = $('.inputFilter').on('input blur', function () {
var value = $.trim(this.value);
$inputs.not(this).prop('disabled', value.length != 0);
})
})
演示:试试看
jQuery(function(){
var $inputs = $('.inputFilter').on('input blur', function () {
var value = $.trim(this.value);
$inputs.not(this).prop('disabled', value.length != 0);
})
})
演示:试试看
jQuery(function(){
var $inputs = $('.inputFilter').on('input blur', function () {
var value = $.trim(this.value);
$inputs.not(this).prop('disabled', value.length != 0);
})
})
演示:试试这个
$('.inputFilter').change(function(){
if($(this).val() == "")
{
$('.inputFilter').removeProp('disabled');
}
else
{
$('.inputFilter').not($(this)).prop('disabled',true);
}
});
试试这个
$('.inputFilter').change(function(){
if($(this).val() == "")
{
$('.inputFilter').removeProp('disabled');
}
else
{
$('.inputFilter').not($(this)).prop('disabled',true);
}
});
试试这个
$('.inputFilter').change(function(){
if($(this).val() == "")
{
$('.inputFilter').removeProp('disabled');
}
else
{
$('.inputFilter').not($(this)).prop('disabled',true);
}
});
试试这个
$('.inputFilter').change(function(){
if($(this).val() == "")
{
$('.inputFilter').removeProp('disabled');
}
else
{
$('.inputFilter').not($(this)).prop('disabled',true);
}
});
您可以根据需要使用jQuery.each():
function disableAllButX(x){
$.each( $('input[type=text]') , function( i, element ){
if(i!=x){
element.disabled=true;
} else {
element.disabled=false;
}
});
}
对于HTML:
<input type="text" class="inputFilter" id="input1" name="input1" value="A" />
<input type="text" class="inputFilter" id="input2" name="input2" value="B" />
<input type="text" class="inputFilter" id="input3" name="input3" value="C" />
并通过某个触发器调用它(即onclick或onchange):
您可以根据需要使用jQuery.each():
function disableAllButX(x){
$.each( $('input[type=text]') , function( i, element ){
if(i!=x){
element.disabled=true;
} else {
element.disabled=false;
}
});
}
对于HTML:
<input type="text" class="inputFilter" id="input1" name="input1" value="A" />
<input type="text" class="inputFilter" id="input2" name="input2" value="B" />
<input type="text" class="inputFilter" id="input3" name="input3" value="C" />
并通过某个触发器调用它(即onclick或onchange):
您可以根据需要使用jQuery.each():
function disableAllButX(x){
$.each( $('input[type=text]') , function( i, element ){
if(i!=x){
element.disabled=true;
} else {
element.disabled=false;
}
});
}
对于HTML:
<input type="text" class="inputFilter" id="input1" name="input1" value="A" />
<input type="text" class="inputFilter" id="input2" name="input2" value="B" />
<input type="text" class="inputFilter" id="input3" name="input3" value="C" />
并通过某个触发器调用它(即onclick或onchange):
您可以根据需要使用jQuery.each():
function disableAllButX(x){
$.each( $('input[type=text]') , function( i, element ){
if(i!=x){
element.disabled=true;
} else {
element.disabled=false;
}
});
}
对于HTML:
<input type="text" class="inputFilter" id="input1" name="input1" value="A" />
<input type="text" class="inputFilter" id="input2" name="input2" value="B" />
<input type="text" class="inputFilter" id="input3" name="input3" value="C" />
并通过某个触发器调用它(即onclick或onchange):
谢谢,这也很好-Arun的解决方案在我的情况下似乎更好。@user2571510 Arun总是更好。:)谢谢,这也很好-Arun的解决方案在我的情况下似乎更好。@user2571510 Arun总是更好。:)谢谢,这也很好-Arun的解决方案在我的情况下似乎更好。@user2571510 Arun总是更好。:)谢谢,这也很好-Arun的解决方案在我的情况下似乎更好。@user2571510 Arun总是更好。:)