input 绑定回车事件

<input type="text" id="message" onkeypress="return onKeyPress(event)" >

function onKeyPress(e)
    {
        var keyCode = null;

        if(e.which)
            keyCode = e.which;
        else if(e.keyCode) 
            keyCode = e.keyCode;
            
        if(keyCode == 13) 
        {
            SendMessage();
            return false;
        }
        return true;
    }
原文:http://blog.163.com/llf_046/blog/static/527371192009219105833741/

你可能感兴趣的:(js)