基于输入框的Javascript页面位置

时间:2014-03-11 19:40:31

标签: javascript html url input

我有一个输入框,您可以在其中输入一个单词,当您单击按钮时,它会带您到该页面后面附加“.html”。

    <input type="button" id="button" name="button" value="GO" onclick="password(this.form)">
    <input type="text" id="answerbox" name="answerbox">

我的JavaScript是:

function password() {
   var password =this.document.answerarea.answerbox.value
   if (password) { this.location.href = password + ".html"; }}

当您单击按钮时,此功能有效,但是当您按Enter键时,页面将重新加载,并在网址后面显示答案(例如/index.html?answerbox=hello) 有没有办法来解决这个问题?感谢。

0 个答案:

没有答案