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 through alexa, and then uses onfocus = "this. value = ''" this code pulls the cursor back to the beginning of textarea, so that it can be easily cleared.
Effect demonstration
Program code
01 |
<Textarea id = "MyTextArea" Name = "Pl" Rows = "5" Style = "Width: 500px ;" Onkeypress = "Send (event )" Onfocus = "This. value = ''" > </Textarea> <br/> |
02 |
<Input id = "ShowBtn" Name = "Button" Type = "Button" Onclick = "Send_bet ();" Value = "Submit" /> |
06 |
Var MyTextArea = document. getElementById ( "MyTextArea" ); |
07 |
MyTextArea. value = '' ; |
08 |
MyTextArea. select (); |
12 |
If (Event. keyCode = 13) |
16 |
MyTextArea. value = '' ; |
If you are used to writing XML, you may write such HTML code:
1 |
< 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.
Remove the carriage return newline character from textarea in IE