javascript - Show what the user typed in the body -
i have code , want after user type in textfield
, press enter, typed appears on screen. i'm not being able that, i'd here.
<!doctype html> <html> <head> <title>tasks day</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <script> alert("when have finished task have click on it."); $(document).ready(function(){ $("p").click(function(){ $(this).hide(); }); }); $(document).keypress(function(e) { if(e.which == 13) { } }); function showmsg(){ var userinput = document.getelementbyid('userinput').value; document.getelementbyid('usermsg').innerhtml = userinput; } </script> </head> <body> <h1>tasks do</h1> <p>type need do:</p> <input type="input" id="userinput" onkeyup=showmsg() value="" /> <p id="usermsg"></p> </body> </html>
it adds 1 value screen, put more one, need create array
- you had main components working. namely, updating screen. have update on
enter
, put code inkeypress
handler - to append value screen(in case of more 1
enter
), concatenate currentinnerhtml
value
$(document).ready(function() { $("p").click(function() { $(this).hide(); }); }); $('#userinput').keypress(function(e) { if (e.which == 13) { var userinput = document.getelementbyid('userinput').value; var innerhtml = document.getelementbyid('usermsg').innerhtml; innerhtml = innerhtml || ''; document.getelementbyid('usermsg').innerhtml += innerhtml + userinput; } });
<title>tasks day</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> <h1>tasks do</h1> <p>type need do:</p> <input type="input" id="userinput" onkeyup=showmsg() value="" /> <p id="usermsg"></p>
Comments
Post a Comment