Today in the writing of a small program, the use of the text box to capture the return key function, I would like to be able to use JavaScript implementation, so Baidu has the following, to get the following implementation.
The HTML page is as follows:
<textarea class= "Form-control" name= "message" id= "message" style= "Display:inline-block;" onkeypress= "onkeypress ( Event) "></textarea> <input type=" button "class=" btn Btn-default "id=" SendMessage "value=" Send "/>
The JS file is implemented as follows:
function OnKeyPress (event) {event = event | | window.event; if (Event.keycode = =) {Event.returnvalue = false; $ (' #message '). Val ("). focus (); }}
At first I was testing with Google Chrome, found all good, but just used IE11 browser test, found that the event can be captured, but the text box was emptied, the cursor another line flashing, that is, in fact, the line is changed, it is strange if I use "shift+ Enter "In a way that works well. Baidu a lot, basically are the above solution, to IE11 no effect. Later find data discovery, also need to add a line of JS code:
Event.preventdefault ();
The above code is the default behavior of blocking events, and obviously IE needs this operation.
This article is from the "jsl_mes" blog, make sure to keep this source http://jslmes.blog.51cto.com/5008224/1604370
The JavaScript implementation enters the ENTER key in the textarea not to break the line