JS获取值&&文本框回车事件

时间:2023-01-17 14:55:19
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <script type="text/javascript">
        //按钮事件
        function WS() {
            var test = document.getElementById("Text1").value;
            alert(test)
        };
        //回车事件
        function Enter(e) {
            if (e.keyCode == 13) {
                alert('click enter');
            }
        };
    </script>
</head>
<body>
    <input id="Text1" type="text" onkeypress="Enter(event)" />
    <input id="Button1" type="button" value="button" onclick="WS()" />
</body>
</html>