<select id="selTest">
<option custom="123" value="abc">111</option>
<option custom="456" value="def">222</option>
<select>
Run Code Online (Sandbox Code Playgroud)
...使用jQuery,如何获得option.custom,其中option.value = selTest.val()
换句话说:如果selTest.val = def,那么$ x = 456(我试图将自定义的值转换为$ x)
试试这个:
var selectedCustomValue = $("select#selTest option:selected").attr("custom");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6492 次 |
| 最近记录: |