Jquery traverses the explanation of the select element of instance

  • 2020-03-30 01:12:01
  • OfStack

This article provides a jquery traversal of the select tutorial code, mainly using $("#< % % = ddl_xreg_id. The clientid > Option ").each(function() {each traverses once, so that all the selects are queried once.


<script src="jquery-1.2.1.js" type="text/ Web page special effects "></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>
<!-- A drop-down box -->
<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>
 Method 2 
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;
            }
        });      
    }


Related articles: