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>
但是什么都没有发生,我期望发生的是当用户单击提交按钮时,从搜索文本框中获取值并将用户重定向到 url + 搜索文本框的值...
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 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 重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!