在文本框中的JavaScript中接受输入密钥

时间:2010-02-24 09:49:25

标签: javascript forms textbox scripting enter

我设置了一个脚本,其中有人通过将漫画附加到URL来选择漫画以从列表中删除。但是,我不能为我的生活让它在文本框内接受输入笔划并仍然保持脚本功能。非常感谢任何解决方案。

脚本/表单如下所示:

function GoToURL(j) { window.status=('Extracting')

var URLis;
 URLis = document.URLframe.Dest.value

   if (URLis == "" || URLis.length <= 0 || URLis > 20 )
       { 
     j.value = "Try Again"
      alert('Pick a comic that exists.');
         window.status=('That comic does not exist.')
           } 
    else
        {
 j.value = "Going" + URLis   
 var location=("aaw" + URLis +".html");
         this.location.href = location;
window.status=('Connecting to ' + URLis + '  Please wait........');
        }
        }
</script>

 <form name="URLframe"> 
<b>Comic #:</b> 
<input type="TEXT" name="Dest" size="5" maxlength="3">
<input type="Button" name="Go to" value="Go" onClick="GoToURL(this)">
</form>

var URLis; URLis = document.URLframe.Dest.value if (URLis == "" || URLis.length <= 0 || URLis > 20 ) { j.value = "Try Again" alert('Pick a comic that exists.'); window.status=('That comic does not exist.') } else { j.value = "Going" + URLis var location=("aaw" + URLis +".html"); this.location.href = location; window.status=('Connecting to ' + URLis + ' Please wait........'); } } </script> <form name="URLframe"> <b>Comic #:</b> <input type="TEXT" name="Dest" size="5" maxlength="3"> <input type="Button" name="Go to" value="Go" onClick="GoToURL(this)"> </form>

1 个答案:

答案 0 :(得分:0)

两个建议。

  1. 将您的onclick="GoToURL(this)"事件处理程序移至表单的onsubmit处理程序。
  2. 将您的按钮类型更改为type="submit"