通过从窗体选择选项中选择的按钮按钮打开链接 [英] Open a link via a button press chosen from a form select option
本文介绍了通过从窗体选择选项中选择的按钮按钮打开链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< form> 我有一个小表格,它是使用URL列表动态构建的。
< select>
< option value =google.com> google.com< / option>
< option value =bing.com> bing.com< / option>
< / select>
< button class =btntype =button> Go!< / button>
< / form>
点击'Go!'按钮,我想用正确的URL打开一个新窗口。
我很确定我不能通过直接的HTML来做到这一点,但有没有jQuery的方式?
谢谢
解决方案
$('button')。click(function(){
url = $('select')。val();
window.open(url);
});
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
解决方案
$('button').click(function() {
url = $('select').val();
window.open(url);
});
这篇关于通过从窗体选择选项中选择的按钮按钮打开链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文