我想更改下面的代码,以便它在新窗口中打开。尝试使用“window.open”而不是“window.location.href”,但运气不佳。
<form method="get" action="http://www.somesite.com/test/" onSubmit="return false;">
<input type="search" name="q" value="" />
<input type="submit" onClick="window.location.href=this.form.action + this.form.q.value;" />
</form>
最佳答案
<form method="get" action="http://www.somesite.com/test/" onSubmit="return false;">
<input type="search" name="q" value="" />
<input type="submit" onClick="window.open(this.form.action + this.form.q.value); "/>
</form>
或
<form method="get" action="http://www.somesite.com/test/" target="_blank">
<input type="search" name="q" value="" />
<input type="submit"/>
</form>
我不确定您需要哪一个。
关于javascript - 使用js在新窗口中打开搜索表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33191931/