如果有条件,我需要一些关于jquery的帮助.我一直在搜索和测试几个小时,任何帮助都会很棒!!! 我得到这个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>
Run Code Online (Sandbox Code Playgroud)
和这个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');
});
}
Run Code Online (Sandbox Code Playgroud)
我是jquery的初学者,我不知道这段代码是否写得正确,因为它不起作用.
问题是:
当输入值小于3时,select2中的select选项与select1中的相同,select2中的其余选项则禁用.当输入值大于3时,select1和select2中的选项将启用.
最诚挚的问候,感谢您阅读这篇jquery新手帖...
art*_*twl 21
试试这个:
$(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);
}
});
});
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/qhPp7/2/
| 归档时间: |
|
| 查看次数: |
77802 次 |
| 最近记录: |