我有一个输入文本框和一个搜索提交按钮,当用户点击搜索提交按钮时,我想将用户重定向到url http://testsearch/results.aspx?k=<value of text box k>
,例如,如果用户将“StackOverflow”放入文本框中,然后单击搜索按钮,我想用户重定向到以下页面,html button v.s. html提交?
http://testsearch/results.aspx?k=StackOverflow
我发现当我使用按钮搜索按钮,它的工作原理(见下文源代码),
<input type="text" id="k" name="k" />
<input type="button" id="Go" value="Search" onclick="location.href = 'http://somemachine/Search/results.aspx?k='+document.getElementById('k').value;"/>
但是当我使用提交搜索按钮,它不起作用(见下面s为什么?)
<input type="text" id="k" name="k" />
<input type="submit" id="Go" value="Search" onclick="location.href = 'http://somemachine/Search/results.aspx?k='+document.getElementById('k').value;"/>
由于事先 乔治
这两个代码示例似乎都是相同的 – naivists 2009-12-30 10:07:14
我不明白“按钮”的情况如何工作,如果您不在onclick事件中放置任何代码。这是完整的例子吗? – helios 2009-12-30 10:13:48
纠正我的示例,谢谢! – George2 2009-12-30 10:23:47