jQuery – 禁用/启用选择选项
如果有条件,我需要一些关于jquery的帮助。 我一直在搜索和测试几个小时,任何帮助都会很棒!!! 我得到这个HTML代码:
No Match Test Test 2 Test 3 No Match Test Test 2 Test 3
这个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/