First, it is not a simple problem!
Values:
$ ("# Textarea"). text (); // read
In recent tests, we found that textArea values cannot be read in firefox or Chrome, and IE is normal.
Therefore, it is changed:
$("#textarea").val();
Solve the problem. However, when searching, someone found another problem:
When you type a carriage return in a textarea tag, two symbols are inserted: \ n \ r \ n carriage return \ r linefeed.
If you use text () to obtain the value in textarea, the data stored in the database will only have \ r. If you use var () to obtain the value in textarea,
The difference between \ n and the data stored in the database is that in IE,
If you read the data stored in text () and are displayed in textarea, the line feed of the data is normal.
The data stored in var () is read and displayed in textarea, so there is no line feed for the data.
It does not seem appropriate to use val () without a specific test. But this is also a required strategy.
Value assignment:
Check the Code:
$("" + "").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, no matter whether set with val () or text (), subsequent reads will be normal. However, in Firefox, the image will appear with the value specified by val, however, text () or html () is a string. Therefore, in Firefox, if you want to set the textarea value to appear in html () or can be cloned (), use text.
And slow. If things are so simple, even elementary school students will be cross-browser. Note the line feed when using text () settings. If you use text ("A \ nA") in IE, only an empty grid is displayed, but no line feed is displayed. According to the test results, text ("A \ r \ A") in IE is close to expectation, but text ("A \ rA ") columns will be changed when displayed in Firefox, but are connected when retrieved using text... this... this... this...
Finally, we can only adopt the cowardly policy. We did this before calling. clone () to avoid the problem:
$theDiv.find("textarea").each(function() { $(this).text($(this).val()); });
Ugly, But it seems effective! If someone has other good ideas, share them with me!
[Tips] You are not capable of being a trojan. Don't tell others that you will "Cross" browsers!