Jquery attr 方法获取option属性值 能者进
<html>
<head>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("button").click(function(){
alert($("select ").attr("label"));
});
});
</script>
</head>
<body>
<select name="istallocal" id="istallocal">
<option label="100" value="">请选择</option>
<option label="101" value="01">01</option>
<option label="102" value="02">02</option></option>
</select>
<br />
<button>返回图像的宽度</button>
</body>
</html>
------解决方案--------------------alert($("select ").attr("label")); select里面没有label标签,打印不出来吧?
$("#istallocal").each(function(){
alert($("option").attr("label"));
});
------解决方案--------------------$(document).ready(function(){
$("button").click(function(){
var s = '';
$("select ").find("[label]").each(function() {
s += $(this).attr("label") + "\n";
});
alert(s);
});
});
------解决方案--------------------$(document).ready(function(){
$("button").click(function(){
var label = $("#istallocal option:selected").attr('label');
alert(label)
});
});