我想创建一个搜索,从我的网站搜索其他网站,问题是其他网站正在使用-而不是+例如:https://somewebsite.com/?search=example-search-query
,但是当我使用此代码时:
<form class="example" method="get" action="https://europixhd.io/svop2/zznewsrv4" style="margin:auto;max-width:300px">
<input type="text" placeholder="Movie Name Here..." name="search">
<button type="submit"><i class="fa fa-play"></i></button>
</form>
[它当然添加+而不是-任何帮助将不胜感激,谢谢!
使用绑定到提交动作的功能
<html>
<form class="example" method="get" action="" id="formID" style="margin:auto;max-width:300px">
<input type="text" placeholder="Movie Name Here..." name="search" id="search">
<button type="submit" ><i class="fa fa-play"></i></button>
</form>
</html>
<script>
var form = document.querySelector('#formID');
form.addEventListener('submit', searchUpdater);
function searchUpdater() {
var text = document.getElementById("search").value.replace(" ", "-");
document.getElementById("search").value = text;
return true;
}
</script>
哦!我已经找到答案了!
<form class="example" method="get" action="" id="formID" style="margin:auto;max-width:300px">
<input type="text" placeholder="Movie Name Here..." name="search" id="search">
<button type="submit" ><i class="fa fa-play"></i></button>
</form>
</html>
<script>
var form = document.querySelector('#formID');
form.addEventListener('submit', searchUpdater);
function searchUpdater() {
var text = document.getElementById("search").value.replace(" ", "-");
document.getElementById("search").value = text;
return true;
}
</script>