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

时间:2013-12-31    点击:97   

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

利用javascript判断文件是否存在
jquery实现checkbox全选全不选的简单实例
屏蔽IE弹出"您查看的网页正在试图关闭窗口,是否关闭此窗口"的方法
JavaScript的常见兼容问题及相关解决方法(chrome/IE/firefox)
IE与FireFox的JavaScript兼容问题解决办法
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved