使用jquery获取自定义标记值

Joe*_*ack 4 jquery

<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)

Tim*_*ren 6

试试这个:

var selectedCustomValue = $("select#selTest option:selected").attr("custom");
Run Code Online (Sandbox Code Playgroud)