gpt4 book ai didi

javascript - 使用 Google 搜索 HTML

转载 作者:行者123 更新时间:2023-12-03 03:06:53 30 4
gpt4 key购买 nike

我正在尝试使用 Google 使我的网站上的搜索功能正常工作。下面是 HTML:

<!-- Start Search -->
<div class="top-search">
<div class="container">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-search"></i></span>
<input id="search" type="text" class="form-control" placeholder="Search">
<span class="input-group-addon close-search"><i class="fa fa-times"></i></span>
</div>
</div>
</div>
<!-- End Search -->

JS:

<!-- Search JavaScript -->
<script type="text/javascript">
document.getElementById('form-control').onsubmit = function() {
window.location = 'http://www.google.com/search?q=site:mywebsite.co.uk ' + document.getElementById('search').value;
return false;
}
</script>
<!-- End Search Javascript -->

最佳答案

您需要一个<form>元素顺序为onsubmit要触发的事件。包裹<input>表单中的元素,它将起作用。

<form>
<!-- Start Search -->
<div class="top-search">
<div class="container">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-search"></i></span>
<input id="search" type="text" class="form-control" placeholder="Search">
<span class="input-group-addon close-search"><i class="fa fa-times"></i></span>
</div>
</div>
</div>
<!-- End Search -->
</form>

关于javascript - 使用 Google 搜索 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47127136/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com