Jquery如何获取select选中项 自定义属性的值?
HTML code
<select id="ddl" onchange="ddl_change(this)"">
<option value="100" emoney="12" gmoney="12">日卡</option>
<option value="102" emoney="58" gmoney="58">月卡</option>
<option value="103" emoney="518" gmoney="518">年卡</option>
<select>
JScript code
function ddl_change(obj){
alert($("#ddl").attr("emoney"));
}
Jquery如何获取select选中项 自定义属性的值?
得出的是undefined!!
怎么获取select选中项中的自定义属性“emoney”的值!??
------解决方案--------------------------------------------------------
$("#ddl").find("option:selected").attr("emoney");
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="jquery-1.8.1.min.js"></script>
<script type="text/javascript">
$(function(){
$('#lev').change(function(){
$('#lev2').html('<option value="1" lev2="1">1</option><option value="2" lev2="2">2</option><option value="3" lev2="3">3</option><option value="4" lev2="4">4</option><option value="5" lev2="5">5</option>');
alert($('#lev').find('option:selected').attr('lev'));
$('#lev').find('option:selected').attr('selected', 'selected');
});
$('#lev2').change(function(){
alert($('#lev2').find('option:selected').attr('lev2'));
$('#lev2').find('option:selected').attr('selected', 'selected');
});
})
</script>
</head>
<body>
<select id="lev">
<option value="1" lev="1">1</option>
<option value="2" lev="2">2</option>
<option value="3" lev="3">3</option>
<option value="4" lev="4">4</option>
<option value="5" lev="5">5</option>
</select>
<select id="lev2">
</select>
</body>
</html>