A recent project has been used in a strange way, using a label to display HTML content, and then continue to use JS to copy the label's innerHTML into a textbox.
However, yesterday found a problem, get the element value, sometimes normal, sometimes not normal, and then into the long Debug.
During debugging, the values of the label and TextBox are monitored, and the value obtained to the label is not changed, and the control is loaded with a SPAN element, which can be seen when viewing the source code of the Web page. However, in the background no matter how to get is the page loaded with the value of the previous unmodified.
While the value of the textbox, although through the JS assignment can always get to the latest value, but the inside properties a lot of double quotes are missing, and some properties of the double quotation marks are retained, do not know why.
The textbox is the INPUT element in the Web page, and then I wonder if the textbox is not suitable for storing HTML code, and then changed the label, HiddenField, Div, RenderControl, and so on, but none of them succeeded.
Although it is normal to view the innerHTML code of the div in the Web page, it cannot be extracted from the server, only to find another way.
Then I use the most primitive way, using the alert to innerHTML output, the results found that the result of alert is also no double quotation marks, it is intriguing, is it innerhtml automatically put double quotes to remove it? So how do I get him to show up normally?
Tried for a long time, to find a way to convert HTML into XHTML, and ultimately ended up in failure.
Try to try, with a lot of different data, try different input, found that there is a property sometimes contains double quotes, and sometimes not, I immediately realize that this is a breakthrough!
Then, emperor, after repeated attempts and observations, I found the law of innerthtml, originally the attribute value contains a space, the property of the double quotation marks, no is not preserved .
With this rule, the next question is handled, why didn't I observe the detail in the beginning?
When using innerHTML to get HTML code, the double quotation marks of HTML tag properties disappear, so the double quotation marks are preserved when the property value contains a space.