0

我有这个代码:

<form>
   <input type="text" placeholder="Enter something..." id="box">
   <button onclick="window.open('http://example.com/' + document.getElementById('box').value);">GO
   </button>
</form>

当用户输入一个单词并单击“GO”时,他会转到一个 url+ 输入的值。使用此代码,页面在新窗口中打开,但我想在同一框架中打开它。我该怎么做?

4

3 回答 3

2
window.open ('page2.htm','_self',false)
于 2013-03-14T13:55:17.253 回答
1

尝试以下

window.open('http://example.com/' + document.getElementById('box').value,'_self')

所以你的代码会是这样的

<form>
   <input type="text" placeholder="Enter something..." id="box">
   <button onclick="window.open('http://example.com/' + document.getElementById('box').value, '_self');">GO
   </button>
</form>
于 2013-03-14T14:02:19.447 回答
0

您可以使用 javascript。

window.location = 网址 + 文本;

于 2013-03-14T13:55:32.073 回答