<body>
<select name="song">
<option>--歌曲--</option>
<%for(int i=0;i<4;i++){ %>
<option>歌曲<%=i %></option>
<%} %>
</select>
<select name="movie">
<option value="">--电影--</option>
<%for(int i=0;i<4;i++){ %>
<option id="ID电影<%=i %>">电影<%=i %></option>
<%} %>
</select>
<select name="book">
<option value="">--书--</option>
<%for(int i=0;i<4;i++){ %>
<option>书<%=i %></option>
<%} %>
</select>
<button id="getValue">获取select中的值</button>
<script type="text/javascript" src="jquery-1.5.1.js"></script>
<script type="text/javascript">
$(function(){
$("#getValue").click(function(){
// 最原始的获取下拉列表中的属性值
// var getselectValueById = $("[name=movie]").find("option").filter(":selected").attr('id');
var song = getSelectValue("song","value");
var movie = getSelectValue("movie","id");
var book = getSelectValue("book","value");alert(song+movie+book);});
// 参数下拉列表的name值,需要取得的option中的属性
function getSelectValue(selectName,selectProperty){
var selectValue = $("[name='"+selectName+"']").find("option").filter(":selected").attr(selectProperty);
// 可以再加上但selectValue为undefined的时候判断和处理
return selectValue;
}
});
</script>
</body>
获取下拉列表中的属性值
最新推荐文章于 2023-07-02 17:20:56 发布