asp.net點選鍵盤enter鍵,呼叫按鈕點選事件函式

穀子Guzii發表於2013-06-17

<input id="name" name="name" class="name" type="text"  />

<input id="pwd" name="pwd" type="password" />

<input id="btn" type="button" value="按鈕" />

 

引入<script src="script/jquery-1.7.min.js"></script>

核心函式

    <script type="text/javascript">
        $(function () {
            $("#btn").click(function () {
                var name = $("#name").val();
                var pwd = $("#pwd").val();
                if (name == "admin"&&pwd=="123456") {
                   window.location.href="index.html";
                }
                else {
                    alert("使用者名稱或密碼錯誤!");
                    return;
                }
            })

           //點選鍵盤enter鍵,呼叫上面點選事件

            document.onkeydown = function () {
                var ev = document.all ? window.event : e;
                if (ev.keyCode==13) {
                    $("#btn").click();
                    event.returnValue=false;
                }
            }
        })

    </script>

 

 

相關文章