开发者

Change to a option on click? jQuery

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜