在文本框内的JavaScript中接受enter键
我设置了一个脚本,有人通过将漫画添加到URL,从列表中选择要去的漫画。然而,我无法让它在文本框中接受enter笔划并仍然保持脚本功能。任何解决方案都将不胜感激 脚本/表单如下所示: 函数GoToURLj{ window.status='Extraction'在文本框内的JavaScript中接受enter键,javascript,forms,textbox,scripting,enter,Javascript,Forms,Textbox,Scripting,Enter,我设置了一个脚本,有人通过将漫画添加到URL,从列表中选择要去的漫画。然而,我无法让它在文本框中接受enter笔划并仍然保持脚本功能。任何解决方案都将不胜感激 脚本/表单如下所示: 函数GoToURLj{ window.status='Extraction' var URLis; URLis = document.URLframe.Dest.value if (URLis == "" || URLis.length <= 0 || URLis > 20 )
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>
两个建议
将onclick=GoToURLthis事件处理程序移动到表单的onsubmit处理程序。
将按钮类型更改为type=submit。
使用代替。您还可能希望将onsubmit从HTML中移出,放在window.onload中。