First, it's not a simple question.
First, take the value:
$ ("#textarea"). Text ();//Read
The latest test found in Firefox or Chrome read textarea value, ie normal.
It is then modified to:
$ ("#textarea"). Val ();
Problem solved, but when searching, it was found that someone asked another question:
When you type a carriage return in a textarea tab, you actually insert 2 symbols: \n\r \ r \ n line break
If you use text () to get the value in textarea, then the data stored in the database will have only \ r if you use VAR () to get the value in textarea,
Then the data stored in the database will only have the difference is that, under IE,
If you are reading the data stored in the text () in the display in the textarea, then the line of data is normal.
While reading data stored in VAR () is displayed in the textarea, the data is not wrapped.
It is not appropriate to use Val () without a specific test. But this is also a must to seek the policy.
Besides, the assignment:
Look at the code:
$ ("<div id= ' x1 ' ><textarea id= ' t1 ' ></textarea>" +
"<textarea id= ' T2 ' ></textarea> </div> "). Appendto (" body ");
$ ("#t1"). Text ("AAA"); $ ("#t2"). Val ("BBB");
Alert ("t1=" + $ ("#t1"). Text () + "/" + $ ("#t1"). Val ());
Alert ("t2=" + $ ("#t2"). Text () + "/" + $ ("#t2"). Val ());
Alert ($ ("#x1"). html ());
In IE, the subsequent reads are normal, regardless of the Val () or text (), but in Firefox, the value specified by Val () appears, but the text () or the HTML () view is the string. So in Firefox, if you want to set the textarea value to appear in HTML () or can be clone (), use text (...). Set.
Wait. If things are so simple, even primary school students will cross the browser. Use text () settings should pay attention to the problem of line, if you are in IE next text ("A\na"), in the display will only render empty one and will not wrap. According to my test results, in IE under the text ("A\r\a") to show the results are relatively close to the expected, but text ("A\ra") in Firefox will be displayed in the column, with text () when it is connected together ... This... This... This...
Finally, you can only take a cowardly strategy and do this before calling. Clone ():
Very ugly, but it seems to be effective! If someone has another good idea, share it.
"Experience" does not have the ability to be a horse, do not tell others you will "cross" browser.