<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>获取select框下option所有值</title>
</head>
<script src="js/jquery.min.js"></script> <!-- 确保有此文件 -->
<body>
<select id="test">
<option value="1">手机</option>
<option value="2">路由器</option>
<option value="3">耳机</option>
</select>
<script>
var arr = new Array();
var all = "";
$("#test option").each(function () {
var txt = $(this).text();
var val = $(this).val();
// var node = "<" + txt + ">" + val + "</" + txt + ">"; //<1>手机</1>组合显示
var node = "" + txt + "\n";
arr.push(node);
all += node;
});
alert(all);
alert(arr);
</script>
</body>
</html>
示例图
原创文章,作者:wwh,如若转载,请注明出处:https://www.wuwenhui.cn/5533.html