// 1.
<script type="text/javascript">
function document.onkeydown(){ //网页内按下回车触发
if(event.keyCode==13)
{
document.getElementById("Button").click();
return false;
}
}
</script>
// 2.
<head><meta http-equiv="Content-Type" content="text/html;
charset=gb2312" />
<title>js捕捉回车事件</title><script>
function test(){
if (event.keyCode == 13)
{
alert("捕捉住回车提交事件!");
}
}
</script>
</head>
<body>
<form method="post"> 标题:<input type="text" name="t" onkeydown="test();"/>
</form>
</body>
<script type="text/javascript">
function document.onkeydown(){ //网页内按下回车触发
if(event.keyCode==13)
{
document.getElementById("Button").click();
return false;
}
}
</script>
// 2.
<head><meta http-equiv="Content-Type" content="text/html;
charset=gb2312" />
<title>js捕捉回车事件</title><script>
function test(){
if (event.keyCode == 13)
{
alert("捕捉住回车提交事件!");
}
}
</script>
</head>
<body>
<form method="post"> 标题:<input type="text" name="t" onkeydown="test();"/>
</form>
</body>
本文介绍了一种使用JavaScript来捕获用户在网页表单中按下回车键的方法。通过监听键盘事件并检查事件码是否为13(代表回车键),可以实现特定的功能触发,如提交表单等。
200

被折叠的 条评论
为什么被折叠?



