zl程序教程

您现在的位置是:首页 >  前端

当前栏目

jquery遍历select元素(实例讲解)

jQuery实例遍历 元素 讲解 SELECT
2023-06-13 09:15:15 时间

本篇文章提供一款jquery遍历select教程代码,主要是利用了$("#<%=ddl_xreg_id.clientid%>option").each(function(){形式来each遍历一次,这样所有的select就给查询了一次。

复制代码代码如下:

<scriptsrc="jquery-1.2.1.js"type="text/网页特效"></script>
<scriptlanguage="javascript"type="text/javascript">
$(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($("#selecttestoption[@selected]").text());
      $("#selecttest").attr("value","2");

});
});
</script>


<ahref="#">aaass</a>

<!--下拉框-->
<selectid="selecttest"name="selecttest">
<optionvalue="1">11</option>
<optionvalue="2">22</option>
<optionvalue="3">33</option>
<optionvalue="4">44</option>
<optionvalue="5">55</option>
<optionvalue="6">66</option>
</select>

方法二
functionautoscrollregion(){
       varreg_name=$("#<%=txt_reg_name.clientid%>").val();

       $("#<%=ddl_xreg_id.clientid%>option").each(function(){
       if($(this).text()==reg_name){
               $(this).attr("selected","selected");
               break;
           }
       });     
   }