I have three drop down select lists, when a value from one of the list is selected, I want the other two to be greyed out and inactive. 我在我正在试验的每个选择列表周围都有 id 包装器,但是由于我是 jquery 的新手,所以我并没有走得太远。
问问题
813 次
4 回答
4
像这样的东西应该工作:
$(function() {
var $selects = $('#select1, #select2, #select3');
$selects.change(function() {
// disabled the other two
$selects.not(this).attr('disabled', 'disabled');
});
});
更新后的版本:
$(function() {
var $selects = $('#select1, #select2, #select3');
$selects.change(function() {
// disable or enable the other two
$selects.not(this).attr('disabled', $(this).val() === '' ? '' : 'disabled');
});
});
于 2010-08-10T22:50:57.440 回答
0
你可以这样做:
$('#wrappers').change(function(){
$('#select1').attr('disabled', true);
$('#select2').attr('disabled', true);
});
选择元素的 id在哪里wrappers
,当您从中选择一个值时,其他两个将被禁用,其 id 分别为select1
和select2
例如:
<select id="wrappers">.........
<select id="select1">.........
<select id="select2">.........
于 2010-08-10T22:42:36.877 回答
0
我假设您有三个,如果选择了三个中的任何一个,则其他两个应该禁用。
function toggleOthers(x) {
var select = new Array('#wrapper1','#wrapper2','#wrapper3');
for (int i = 0; i < select.length; i++ )
if ($(x).attr('id')!=select[i])
$(x).attr('disabled','disable');
}
HTML:
<select onchange='toggleOthers(this);' id='wrapper1'> etc...
于 2010-08-10T22:48:53.530 回答
0
如果你有一个带有#wrapper id 的 div 包装器的选择
$('#wrapper select').each(function(i,select){
$(select).change(function(){
$(this).attr('class','enabled').siblings().attr('class','disabled');
})
})
于 2010-08-10T23:04:29.043 回答