Jquery 选择输入顺序
因此,我有3个选择输入字段,我想知道一旦选择了其他选项,是否可以禁用它们。即:Jquery 选择输入顺序,jquery,html,Jquery,Html,因此,我有3个选择输入字段,我想知道一旦选择了其他选项,是否可以禁用它们。即: <tr id="row1"> <th>Row 1</th> <td> <select> <option value="1">1</option> <option value="2" selected>2 selected so 1+3 are
<tr id="row1">
<th>Row 1</th>
<td>
<select>
<option value="1">1</option>
<option value="2" selected>2 selected so 1+3 are disabled</option>
<option value="3">3</option>
</select>
</td>
</tr>
<tr id="row2">
<th>Row 2</th>
<td>
<select>
<option value="1" selected>1 selected 2+3 are disabled</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
</tr>
<tr id="row3">
<th>Row 3</th>
<td>
<select>
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected>3 (you get it...)</option>
</select>
</td>
</tr>
一排
1.
2选定,因此1+3被禁用
3.
第2排
1选定的2+3被禁用
2.
3.
第3排
1.
2.
3(你明白了…)
试试这个:
$('select').change(function(){
$(this).find('option:not(:selected)').prop('disabled', true)
})
试试这个:
$('select').change(function(){
$(this).find('option:not(:selected)').prop('disabled', true)
})
您可以将onchange事件绑定到select。然后选择未选择的选项元素并禁用此选项。如果您已经熟悉jQuery,可以这样做:
$("select").bind("change", function(){
$(this).children("option:not(:selected)").attr("disabled", "disabled");
});
您可以将onchange事件绑定到select。然后选择未选择的选项元素并禁用此选项。如果您已经熟悉jQuery,可以这样做:
$("select").bind("change", function(){
$(this).children("option:not(:selected)").attr("disabled", "disabled");
});
禁用其他选项将阻止用户更改其选择,因此只需使用javascript删除所有其他选项 快速、肮脏的方式是
<select onchange='for(vari=0, l=this.options.length; i<l; i++){ if(this.options[i].selected) continue; this.remove(i); }'>
不需要Jquery。但是,我不会建议将javascript与html混合使用,除非您没有任何其他外部javascript可以导入并将其作为这些特定select语句的处理程序应用。禁用其他选项将阻止用户更改其选择,所以只需使用javascript删除所有其他选项 快速、肮脏的方式是
<select onchange='for(vari=0, l=this.options.length; i<l; i++){ if(this.options[i].selected) continue; this.remove(i); }'>
不需要Jquery。但是,我不建议将javascript与html混合使用,除非您没有任何其他外部javascript可以导入并应用它作为这些特定select语句的处理程序。如果您在选择一个选项后禁用其他选项,用户应该如何更改其选择?@MattBall我猜是通过取消选中框来进行的,但这是一个奇怪的用户体验。我相信您要查找的是单选按钮,而不是选项选择。如果您在选择一个选项后禁用其他选项,用户应该如何更改其选择?@MattBall我猜是通过取消选中框来进行的,但这是一个奇怪的用户体验。我相信你要找的是单选按钮,而不是选项选择老明星!金星!