用JQuery如何遍历多个select的同时遍历每一个select的option? 如题,还有一个问题就是如何在遍历option的时候取select的id,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 $("select").each(function(){ var myid=$(this).attr(id); $(this).find("option").each(function(){ alert("此option的值为"+$(this).val()+",他上面的select的ID为"+myid); });}); <!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> 还有一种写法:$('select').each(function() { alert($(this).children("option:selected").val()); }); javaScript的this,及call函数 哪位童鞋有jquery autocomplete支持拼音和首字母的例子?最好是php环境。 请大家帮我解释一下上面的代码! JS文件中文出现乱码? 梅花雪树1.0,有没有办法关闭节点? 请帮忙! 异步下载js时,下载失败如何得到错误状态并回调错误处理函数 td高度的设置 请教高手怎么样用JS刷新2个iframe页面? 提问一个关于div问题 onafterpaste 无效 YUI panel在IE不能正常显示
var myid=$(this).attr(id);
$(this).find("option").each(function(){
alert("此option的值为"+$(this).val()+",他上面的select的ID为"+myid);
});
});
<!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>
$('select').each(function()
{
alert($(this).children("option:selected").val());
});