get index of Select Option from Text value
I can't recall how to get the index of the option from the text without using a for loop. Is there an easy way?
Let's say I have a select like this:
<select id="prefix-select" name="survey[Prefix]" onchange="changeMade();">
<option value="0">Mr.</option>
<option value="1">Mrs.</option>
<option value="2">Ms.</option>
<option value="3">Dr.</option>
<option value="4">Sr.</option>
<option value="5">Sra.</option>
<option value="6">Srta.</option>
</selec开发者_高级运维t>
Now I want to get the index when I have a text of '.Ms'
Jquery way:
var str = "Sr."; index = $("#prefix-select > option:contains("+str+")").index())
精彩评论