我正在尝试创建一个主页,我可以将其设置为浏览器主页。 以下是"谷歌搜索"只有当您点击Google按钮时才会打开谷歌的功能。当我按下"输入"在文本区域,它重新加载我的页面。
我的问题是每当我按"输入"在键盘上,它只是重新加载页面,而不是用我放入框中的任何单词打开谷歌。
我想通过按Enter或Google按钮,谷歌打开我的搜索框所说的任何内容。
<form>
<input class="form-control radius-input" id="textbox" type="text" placeholder="Search on Google..." onkeydown="if (event.keyCode == 13 || event.which == 13) { location='http://www.google.com/search?q=' + encodeURIComponent(document.getElementById('textbox').value);}" />
<a class="btn btn-common btn-lg pull-right " id="googleLink" href="notrequired" onclick="this.href='http://www.google.com/search?q=' + encodeURIComponent(document.getElementById('textbox').value);">
<span>Google</span>
</a>
</form>
如果您需要更具体的背景,请告诉我,我会尽我所能。
非常感谢你。
答案 0 :(得分:-1)
我所要做的就是删除表格标签。
工作原理如下:
<input class="form-control radius-input" id="textbox" type="text" placeholder="Search on Google..." onkeydown="if (event.keyCode == 13 || event.which == 13) { location='http://www.google.com/search?q=' + encodeURIComponent(document.getElementById('textbox').value);}" />
<a class="btn btn-common btn-lg pull-right " id="googleLink" href="notrequired" onclick="this.href='http://www.google.com/search?q=' + encodeURIComponent(document.getElementById('textbox').value);">
<span>Google</span>
</a>