使用jquery获取自定义标记值

 111 222  

…使用jQuery, 如何获得option.custom,其中option.value = selTest.val()

换句话说:如果selTest.val = def,那么$ x = 456(我试图将自定义的值转换为$ x)

试试这个:

 var selectedCustomValue = $("select#selTest option:selected").attr("custom"); 
 var selectElement = $("#selTest")[0]; alert(selectElement.options[selectElement.selectedIndex].getAttribute("custom")); 

请尝试以下方法

 $('#selTest').change(function() { var value = $(this).val(); var custom = $('option[value="' + value +'"]').attr('custom'); ... });