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">
       alert($("#selecttest option[@selected]").text());
       $("#selecttest").attr("value", "2");

<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>
 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");

Related articles: