×

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

作者:Terry2017.02.10来源:Web前端之家浏览:10257评论:0
关键词:JQueryJS

本篇文章提供一款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;
            }
        });     
    }

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://www.jiangweishan.com/article/svg1486656000833.html

网友评论文明上网理性发言已有0人参与

发表评论: