我需要一些关于jquery if条件的帮助。我已经搜索和测试了几个小时,任何帮助都会很好!我得到了这个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 option与select1中的select option相同,而select2中的其余选项将被禁用。当输入值大于3时,将启用select1和select2中的选项。
致以最好的问候,感谢您阅读这篇jquery新手文章...
发布于 2012-07-24 19:35:01
试试这个:
$(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);
}
});
});https://stackoverflow.com/questions/11629669
复制相似问题