In textarea, press enter to generate the Escape Character \ r \ n. In some cases, we do not need these two escape characters, that is, clearing textarea. The following method is not empty, but can achieve similar results.
If you press enter in textarea and the content is submitted, the escape characters \ r \ n will be left in textarea, And the cursor will be in the second line. The following program transfers the focus out through alexa, and then pulls the cursor back to the very beginning of textarea through the onfocus = "this. value ='' "code, so that it can be easily cleared.
Effect demonstration
Program code
<Textarea id = "myTextArea" name = "pl" rows = "5" style = "width: 500px;" onkeypress = "send (event)" onfocus = "this. value = ''"> </textarea> <br/> <input id = "showBtn" name = "button" type = "button" onclick = "send_bet (); "value =" Submit "/> <script> function send_bet () {var myTextArea = document. getElementById ("myTextArea"); myTextArea. value = ''; myTextArea. select ();} function send (event) {if (event. keyCode = 13) {send_bet (); alert ("submitted successfully"); myTextArea. value = ''; myTextArea. focus () ;}</script>
If you are used to writing XML, you may write such HTML code:
<textarea name="test" cols="20" rows="4" />
The result is that the HTML after textarea appears in the text field as the content. This is the first funny part. It does not support common mark termination methods;
Next, I added the value = "test" attribute to this textarea. In fact, nothing can be seen in the text field, however, the following Javascript statement can change the content displayed in the text field: document. forms [0]. test. value = "test"; this is the second funny place;
The last funny part is the most exaggerated. Generally, spaces in HTML are ignored. However, spaces between the start and end labels of textarea are all received in the text field as the default input of textarea. As I am used to writing HTML, I like to write two corresponding tags in two rows, and the result can be imagined. No matter what, when I focus on the TextArea text field, the cursor is not displayed on the far left, which is not very important. Even worse, because of the existence of these spaces, when the input content is not on the edge of the text field, it will automatically wrap, unless you delete all spaces entered by default.