qq_42998816 2021-08-31 16:20 采纳率: 18.2%
浏览 23
已采纳

按回车键,焦点切换到下一个文本框。为什么实现不了?如何修改能实现?

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>enter_to_next</title>
</head>
<body>
    <form action="" name="form1">
        username: <input type="text" name="username" id="" onkeypress="myEnter(form1.password)"><br>
        password: <input type="password" name="password" id="" onkeypress="myEnter(form1.tel)"><br>
        tel:  <input type="text" name="tel" id="" onkeypress="myEnter(form1.submit)"><br>
        <input type="reset"><br>
        <input type="submit" name="submit"><br>
    </form>
    <script>
        /* 按回车键,焦点切换到下一个文本框。 */
        function myEnter(str){
            if(event.keyCode==13)
                str.focus();
        }
    </script>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • limit、T 2021-08-31 16:34
    关注

    你按的是回车,我出发的是tab

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已采纳回答 3月11日
  • 创建了问题 8月31日