Jquery如何获取select选中项 自定义属性的值?
HTML code
JScript code
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="http://www.likecs.com/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>
<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>
</select>
</body>
</html>