【问题标题】:HTML Input ButtonHTML 输入按钮
【发布时间】:2013-07-03 19:46:08
【问题描述】:

我在这里使用这个代码:

<input type="button"  value="Latest Results" onClick="self.location='http://URL.COM/SEARCH STRING'+document.getElementById('code').value +'EXTRA BIT OF SEARCH URL'">

我使用输入框(有时是几个输入框)来获取输入并快速将其添加到 URL 以搜索内部系统。它非常适合我们需要的东西,但我试图让它在新窗口而不是当前窗口中打开。

我尝试将 target="_blank" 添加到末尾并将 onClick="self.location= 更改为 window.open 但没有运气。

【问题讨论】:

  • 你试过用 window.open 代替 self.location 吗?
  • 检查这个:jsbin.com/ocoqid/1
  • 试试&lt;input type="button" value="Latest Results" onClick="window.open('http://URL.COM/SEARCH STRING'+document.getElementById('code').value +'EXTRA BIT OF SEARCH URL', '_blank')"&gt;
  • @PiLHA window.open 作为它的第二个参数有默认的_blank :P
  • @MohammadAreebSiddiqui 谢谢 :)

标签: html forms button onclick


【解决方案1】:

试试这个:

<input type="button"  value="Latest Results" onClick="window.open('http://www.google.com');">

使用window.open 而不是self.location :)

jsBin.

【讨论】:

  • 你应该使用 JSfiddle 而不是 jsBin...它有一个更好的界面,以便 OP 可以看到实际发生的情况
  • @pattyd 它有!让我给你一个例子:)
  • 啊-我没有尝试 window.open 和括号。这就是我想要的——谢谢。
猜你喜欢
  • 2013-05-16
  • 1970-01-01
  • 2011-03-17
  • 2018-12-06
  • 1970-01-01
  • 2012-01-27
  • 1970-01-01
  • 1970-01-01
  • 2012-11-29
相关资源
最近更新 更多