开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜