Remove the carriage return newline character from textarea in IE

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.