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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2020-05-13 我要评论

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

复制代码 代码如下:

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

});
});
</script>


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

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

方法二
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;
            }
        });     
    }

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们