<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题pj文档</title> <script> window.onload = function() { var oText=document.getElementById('text1'); var oUl=document.getElementById('ul1'); oText.onkeyup=function(ev) { ev=ev||event; if(oText.value!='') { if (ev.keyCode == 13) { var oLi = document.createElement('li'); oLi.innerHTML = oText.value; if ( oUl.children[0] ) { oUl.insertBefore( oLi, oUl.children[0] ); } else { oUl.appendChild( oLi ); } } } } }; </script> </head> <body> <input type="text" id="text1"/> <ul id="ul1" ></ul> </body> </html>