How to open a link in a select box in a new window?

和自甴很熟 提交于 2020-01-06 09:54:41

问题


How can I open each link in this select box in a new window?

<form name="jump">
<select name="menu">
<option value="http://">link</option>
<option value="http://">link</option>
<option value="http://">link</option>
</select>
<input type="button" onClick="location=document.jump.menu.options[document.jump.menu.selectedIndex].value;" value="GO" />
</form>

回答1:


The correct function for a new window is window.open();

<form name="jump">
    <select name="menu">
       <option value="http://">link</option>
       <option value="http://">link</option>
       <option value="http://">link</option>
       </select>
       <input type="button" id="button"
       onclick="window.open(document.jump.menu.options[document.jump.menu.selectedIndex].value);" value="GO" />
</form>

Note: Writing in line javascript can be messy. try separating your javascript from your presentation



来源:https://stackoverflow.com/questions/13571718/how-to-open-a-link-in-a-select-box-in-a-new-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!