我有一个选择框,其中包含动态加载的各种选项。我正在编写代码来迭代代码,如果文本值是特定值示例(在本例中为 8065992445),则将其设为默认选项。没有办法做到这一点。
$("#locationselect > option").each(function() {
if(this.text==8065992445)
});
最佳答案
使用val获取选择选项值的方法:
$("#locationselect > option").each(function() {
if($(this).val()==8065992445){
//do your task...
}
});
关于javascript - 如何获取选择框中给定选项的索引值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37433520/