我正在尝试做一个搜索引擎。
我以为它会重定向我。这是我的代码
<!doctype html>
<script>
function show(){
s=searchForm.searchField.value;
window.location.replace("https://www.google.com/search?q="+searchField);
}
</style>
<form id="searchForm">
<input type="search" name="searchField" placeholder="Search QuickSearch">
<input type="submit" value="Search" onclick="show()">
</form>
我认为你想做的事情是这样的:
JS:
function show() {
const s = document.getElementById('inputId').value;
window.location.replace("https://www.google.com/search?q=" + s);
}
HTML:
<form id="searchForm" onsubmit="event.preventDefault()">
<input type="search" name="searchField" id="inputId" placeholder="Search QuickSearch">
<input type="submit" value="Search" onclick="show()">
</form>