我正在尝试为网站创建搜索输入,将搜索字词添加到网址的末尾。
这是有问题的网址:
http://apps.ticketbiscuit.com/ticketbiscuit.website/LyricTheatreOxford/Search/
您可以通过将搜索字词添加到网址的末尾来手动搜索eg./Search/robert&如果字符串包含多个单词,则需要用“%20”分隔,例如/Search/Robert%20Earl。
这是我目前的搜索表单:
<form method="get" action="http://apps.ticketbiscuit.com/ticketbiscuit.website/LyricTheatreOxford/Events/Search/" id="searchform" role="search">
<input type="text" value="Search Events" name="s" id="s" onFocus="if (this.value == 'Search Events') {this.value=''; this.style.color='#000000';}"/>
<input type="hidden" name="sitesearch" value=""/>
</form>
如果我在输入中输入Kevin,表单将返回此url:
http://apps.ticketbiscuit.com/ticketbiscuit.website/LyricTheatreOxford/Search/?s=Kevin&sitesearch=
我知道我需要一些Javascript来处理搜索并构建正确的网址,但我不知道需要什么。
有人有什么想法吗?如果在别处得到回答,请道歉。我长时间环顾四周但找不到任何东西。
答案 0 :(得分:0)
将onsubmit="return searchForm(this)"
添加到表单标记。
然后,定义function searchForm
:
<script>
function searchForm(form){
location.href = "http://apps.ticketbiscuit.com/ticketbiscuit.website/LyricTheatreOxford/Search/" + form.s.value;
return false;
}
</script>
另请参阅:Open a URL based on search query without php "?q=(myTerm)" and instead with a simple "/(myTerm)"