禁用基于值的选择选项*仅通过 HTML!* [英] Disable select options based on value *through the HTML only!*
本文介绍了禁用基于值的选择选项*仅通过 HTML!*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要根据变量的值禁用选择选项.该值类似于选择选项值之一,需要禁用.
I need to disable a select option based on the value of a variable. The value is similar to one of the select option value and it needs to be disabled.
例如,
<select>
<option>Value a</option>
<option>Value b</option>
</select>
$variable = <some select option value>;
因此,如果变量等于 Value a,则需要在选择选项中禁用它.
So if variable is equal to Value a then it needs to be disabled in select option.
谢谢.
推荐答案
使用您当前的标记,这将起作用:
With your current markup this will work:
$("select option:contains('Value b')").attr("disabled","disabled");
编辑
var variable = "b"
$("select option:contains('Value " + variable + "')").attr("disabled","disabled");
$("select").prop("selectedIndex",-1)
这篇关于禁用基于值的选择选项*仅通过 HTML!*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文