87,910
社区成员
发帖
与我相关
我的任务
分享
$('select').each(function()
{
alert($(this).children("option:selected").val());
});
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
<script src="jquery-1.3.2.js"></script>
<script>
$(function(){
$("select").each(function(){
$(this).children("option").each(function(){
alert($(this).text())//每一个option
alert($(this).text()+"属于id为"+$(this).parent("select").attr("id")+"的select");
});
});
});
</script>
</head>
<body>
<select id="test1">
<option>1111</option>
<option>2222</option>
<option>3333</option>
</select>
<select id="test2">
<option>aaaa</option>
<option>bbbb</option>
<option>cccc</option>
</select>
<select id="test3">
<option>一</option>
<option>二</option>
<option>三</option>
</select>
</body>
</html>