Open a link via a button press chosen from a form

2019-07-21 19:55发布

I have a small form which is dynamically built using a list of URLs.

<form> 
  <select>
    <option value="google.com">google.com</option>
    <option value="bing.com">bing.com</option>
  </select>
  <button class="btn" type="button">Go!</button>
</form>

By hitting the 'Go!' button I would like to open a new window with the correct URL.

I'm pretty sure I can't do this through straight HTML but is there a jQuery way?

Thanks

1条回答
贼婆χ
2楼-- · 2019-07-21 20:20
$('button').click(function() {
   url = $('select').val();
   window.open(url);
});
查看更多
登录 后发表回答