1. 程式人生 > >input 繫結回車事件

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/