JavaScript onclick重定向 [英] JavaScript onclick redirect
本文介绍了JavaScript onclick重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个文本字段和按钮
I have this text field and button here
<input name="txtSearch" type="text" id="txtSearch" class="field" />
<input type="submit" name="btnSearch" value="" id="btnSearch" class="btn" onclick="javascript:SubmitFrm()" />
当用户点击提交按钮时,此功能假设运行
and when the user clicks on the submit button this function is suppose to run
<script type="text/javascript">
function SubmitFrm(){
var Searchtxt = document.getElementById("txtSearch").value();
window.location = "http://www.example.com/search/?Query=" + Searchtxt;
}
</script>
但没有任何反应,我期望发生的是当用户点击提交按钮时,来自搜索文本框的值并将用户重定向到网址+搜索文本框的值...
But nothing happens, what I expecting to happen is when the user clicks on the submit button, take the value from the search text box and redirect the user to the url + the value of the search text box...
我做错了什么?
推荐答案
这样做解决了我的问题
<script type="text/javascript">
function SubmitFrm(){
var Searchtxt = document.getElementById("txtSearch").value;
window.location = "http://www.mysite.com/search/?Query=" + Searchtxt;
}
</script>
我将 .value();
更改为 .value;
取出()
I没有更改我的文本字段或提交按钮
I did not change anything in my text field or submit button
<input name="txtSearch" type="text" id="txtSearch" class="field" />
<input type="submit" name="btnSearch" value="" id="btnSearch" class="btn" onclick="javascript:SubmitFrm()" />
像魅力一样工作。
这篇关于JavaScript onclick重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文