本篇文章提供一款jquery遍历select教程代码,主要是利用了$("#<%=ddl_xreg_id.clientid%> option").each(function() {形式来each遍历一次,这样所有的select就给查询了一次。
代码如下:
script>
$(document).ready(function(){
$("#selecttest").change(function()
{
//alert("hello");
//alert($("#selecttest").attr("name"));
//$("a").attr("href","xx.html");
//window.location.href="xx.html";
//alert($("#selecttest").val());
alert($("#selecttest option[@selected]").text());
$("#selecttest").attr("value", "2");
});
});
script>
aaass
方法二
function autoscrollregion() {
var reg_name = $("#<%=txt_reg_name.clientid%>").val();
$("#<%=ddl_xreg_id.clientid%> option").each(function() {
if ($(this).text() == reg_name) {
$(this).attr("selected", "selected");
break;
}
});
}