开发者

Change to a option on click? jQuery

开发者 https://www.devze.com 2023-04-07 13:38 出处:网络
I have a select inside a <开发者_StackOverflow社区tr>. When you click on a link I would like the select change to the option that has value \"00:00\".

I have a select inside a <开发者_StackOverflow社区tr>. When you click on a link I would like the select change to the option that has value "00:00".

I tried myself and came this far:

jQuery(this).parents('tr').find('select')


How about this?

$(this).parents('tr').find('select').val('00:00');


$('#myLink').click(function(e){
  $(this).closest('tr').find('option').val('00:00');
  e.preventDefault();
});

As long as the <select> has an <option ... value="00:00">...</option>, .val() will locate (and select) that <option> for you.

Working Demo showing how .val() finds the <option> (and selects it) for you.

0

精彩评论

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