<script type="text/javascript"> sniffBrowserType(); //Shows loading.. screen showLoadScreen(); //Set the javascript timer and //loads user list and messages setTimers(); setFocus('mytext'); </script> 当用户键入一些信息并回车时,就会调用下面的函数: <input type="text" class="mytext" id="mytext" onkeydown="captureReturn(event)"> // Capture the enter key on the input box and post message function captureReturn( event ) { if(event.which || event.keyCode) { if ((event.which == 13) || (event.keyCode == 13)) { postText(); return false; } else { return true; } } } function postText() { rnd++; //Clear text box first chatbox = getElement( "mytext" ); chat = chatbox.value; chatbox.value = ""; //get user GUID from url userid = location.search.substring( 1, location.search.length ); //construct Ajax Server URL url = 'Server.aspx?action=PostMsg&u=' + userid + '&t=' + encodeURIComponent(chat) + '&session=' + rnd; //Create and set the instance //of appropriate XMLHTTP Request object req = getAjax(); //Update page with new message req.onreadystatechange = function(){ if( req.readyState == 4 && req.status == 200 ) { updateAll(); } } req.open( 'GET', url, true ); req.send( null ); } 就这么多,没什么特别的,你可以看源代码,里面有很多注释信息。 |