我试图找到选项索引基于选项文本。我的HTML代码如下。如何根据选项文本获取选项索引
<select multiple="multiple" onchange="dependentOptions.select(this); opConfig.reloadPrice();optionImages.showImage(this);" title="" class="multiselect product-custom-option" id="select_472" name="options[472][]" >
<option selected="selected" value="3364">Black </option>
<option selected="selected" value="3365">White </option>
<option value="3366">Cool Grey #9 </option>
<option value="3367">Red </option>
<option value="3368">Fire Red </option>
<option value="3369">Orange </option>
<option value="3370">Rich Yellow </option>
<option value="3371">Primrose Yellow </option>
<option value="3372">Light Green </option>
</select>
,我的剧本是这样的
jQuery("#select_472 select option:[text=Rich Yellow]").index();
但它返回我-1 insted的7
所以,请大家帮我SOVE这一点。
第二个'select'在jQuery选择中是错误的,你应该删除它。 – alalp 2014-10-31 11:43:16
其他一些选项在这里:http://stackoverflow.com/questions/813477/jquery-selector-where-text-some-value – Will 2014-10-31 11:51:05
请注意,索引是基于零的,所以在这里它将是6而不是7 – 2014-10-31 11:52:39