简体   繁体   English

在搜索表单上需要帮助

[英]Need help on a Search Form

First post on this site and i am hoping someone can help me. 该网站上的第一篇文章,我希望有人可以帮助我。 I created a search form on my site without a submit button. 我在网站上创建了一个搜索表单,但没有提交按钮。 What i would like to happen is when the user clicks on the search bar it automatically redirects to a new page. 我想发生的是,当用户单击搜索栏时,它会自动重定向到新页面。 I tried an attempt using Javascript but it does not seem to work. 我尝试使用Javascript尝试,但似乎不起作用。 Hoping someone can help me out as i am not familiar with javascript. 希望有人可以帮助我,因为我不熟悉javascript。

<div id="searchbox">
<input type="text" name="search" placeholder="Search.." onClick="redirect('www.triphub.ca')">
</div>


</style>
<script>function redirect('www.triphub.ca')
 {
    window.location.href = www.triphub.ca;
</script>

Thank you 谢谢

You could revise your function to 您可以将功能修改为

function redirect(url)
{ window.location.href = url; }

things inside () are variables and cannot be used as string (like you does wrapped words inside the single quote ' , also you are missing the } at the end of your javascript ()中的东西是变量,不能用作字符串(就像您在单引号'内包裹单词一样,而且您在javascript末尾缺少}

Correct some of mistakes in your code. 更正代码中的一些错误。

 <div id="searchbox"> <input type="text" name="search" placeholder="Search.." onClick="redirect('www.triphub.ca')"> </div> <script> function redirect(url) { window.location.href = url; } </script> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM