开发者

how do you set the value in a dropdown programatically using jquery

开发者 https://www.devze.com 2022-12-24 18:33 出处:网络
if i have a dropdown with the following html:开发者_运维技巧 <select id=\"myDropdown\" name=\"myDropdown\">

if i have a dropdown with the following html:

开发者_运维技巧
 <select id="myDropdown" name="myDropdown">
<option value="6">Six</option>
<option value="5">Five</option>
<option value="3">Three</option>
<option value="1">One</option>
</select>

how can i have this dropdown change to a specific selected value after i click on a button?


If your button is id="myButton" you can do it like this:

$("#myButton").click(function() {
  $("#myDropdown").val(1); //1 being whatever value you want to set
});


try this

  jQuery(document).ready(function(){
      $(".mybuttonclass").click(function() {
           $(".myDropdownclass").val(value for that dropdown items);  
  });
  });
0

精彩评论

暂无评论...
验证码 换一张
取 消