<!DOCTYPE html> <html> <head> <title>Demo</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $("#test").keyup(function(e){ enterTest(e); }); var e = jQuery.Event("keyup");//模擬一個鍵盤事件 e.keyCode =13;//keyCode=13是回車 $("#test").trigger(e); }); function enterTest(e){ if(e.keyCode==13){ alert("Enter"); } } </script> </head> <body> <input id="test" type="text"/> </body> </html>