如果条件,我需要一些
jquery的帮助.
我一直在搜索和测试几个小时,任何帮助将是伟大的!
我得到这个HTML代码:
我一直在搜索和测试几个小时,任何帮助将是伟大的!
我得到这个HTML代码:
<label id="label1" for="date_from">Value:</label> <input value="" /> <select id="select1" name="select1"> <option>No Match</option> <option value="1">Test</option> <option value="2">Test 2</option> <option value="3">Test 3</option> </select> <select id="select2" name="select2"> <option>No Match</option> <option value="1">Test</option> <option value="2">Test 2</option> <option value="3">Test 3</option> </select>
和这个jquery函数:
if ( $('#label1').val() < 3 ) {
$('select').change(function() {
$('#select1,#select2').not(this)
.children('option[value=' + this.value + ']')
attr('disabled',true)
.siblings().removeAttr('disabled');
});
}
else {
$('select').change(function() {
$('#select1,#select2').not(this)
.children('option[value=' + this.value + ']')
.attr('disabled',false)
.siblings().removeAttr('disabled');
});
}
我是jquery的初学者,我不知道这段代码是否正确写入,因为它不起作用.
问题是:
当输入值小于3时,select2中的select选项与select1中的选项相同,并且select2中的其余选项被禁用.当输入值大于3时,select1和select2中的选项将被使能.
最好的问候,谢谢你阅读这个jquery新手帖子…
解决方法
尝试这个:
$(function(){
$("input").change(function(){
if ( $(this).val() < 3 ) {
$('#select2').prop('disabled',true);
$('#select1').on("change",function() {
$('#select2').val($(this).val());
});
}else {
$("#select1").off();
$('#select1,#select2').prop('disabled',false);
}
});
});
演示:http://jsfiddle.net/qhPp7/2/