回车默认提交

回车默认提交

案例一:

$(function(){
            document.getElementById("<%=txtkey.ClientID %>").onkeydown=function(e){
            e=e||window.event;
            var key=e?(e.which||e.keyCode):0;
            if(key==13)
            {
                document.getElementById("<%=btnsearch.ClientID %>").click();
                e.returnValue=false;
                return false;
            }
        }
    });

案例二:

function first() {
            document.getElementById("code1").onkeydown = function (e) {
                e = e || window.event;
                var key = e ? (e.which || e.keyCode) : 0;
                if (key == 13) {
                    document.getElementById("IbtnAdd").click();
                    e.returnValue = false;
                    return false;
                }
            }

            if (document.getElementById("code") != null) {
                document.getElementById("code").onkeydown = loginEnter;
                document.getElementById("upwd").onkeydown = cancelEnter;
            }
            else
                document.getElementById("upwd").onkeydown = loginEnter;

            //取消回车事件
            document.getElementById("uname").onkeydown = cancelEnter;
            document.getElementById("txtregister").onkeydown = cancelEnter;
            document.getElementById("uemail1").onkeydown = cancelEnter;
            document.getElementById("upwd1").onkeydown = cancelEnter;
            document.getElementById("uconfirmpwd1").onkeydown = cancelEnter;
           
        }
        //回车 登录
        function loginEnter(e) {
            e = e || window.event;
            var key = e ? (e.which || e.keyCode) : 0;
            if (key == 13) {
                document.getElementById("lbtnLogin").click();
                e.returnValue = false;
                return false;
            }
        }
        //取消回车事件
        function cancelEnter(e) {
            e = e || window.event;
            var key = e ? (e.which || e.keyCode) : 0;
            if (key == 13) {               
                e.returnValue = false;
                return false;
            }
        }

 

posted on 2010-08-23 17:35  mingfeng  阅读(219)  评论(0编辑  收藏  举报

导航