Gets the text content through HTML (), the form component displays a value that is inconsistent with the obtained value

Source: Internet
Author: User

I get the content of the corresponding node through HTML (), and I find a problem that the content value of the form component is the initial loaded value, not the user-modified value. For example, when a page loads a component <input type= "text" value= "111111"/>, the user changes the form to a value of 222222 and obtains the component through the parent node's HTML () method, which is expected to be <input type= "text "Value=" 222222 "/>, but the result is the initial appearance <input type=" text "value=" 111111 "/>.

After debugging, it is found that changing the value of the form by the user does not change the HTML value of the corresponding form node, but instead changes the value of the property cached in memory (for example, properties) and the browser displays the value of the property. Not the value of the Value property (if textarea is the. html () value). So this problem arises because we mistakenly assume that the value used by the browser display is stored at the beginning of the property used to display the value in the browser (if textarea is the value of. html ().

If you want to make the content obtained through HTML () consistent with the display, you can use a few of the following methods

Some examples of ways to change the value of HTML
$ (". Box_content input[type= ' text ']"). each (function (index, Element) {//input text label
$ (this). attr (' Value ', $ (this). Val ());
});
$ (". Box_content textarea"). each (function (index, Element) {//textarea label
$ (this). The HTML ($ (this). Val ());
});

Then execute $ (". Box_content"). html ();

Note: When the form form uses the Reset method, it is actually the value of the store where the browser display value is used (Input[text] is value,textarea. HTML ()) values are re-assigned to the property that holds the user's modified form value (that is, Val () The location of the value that the method obtains)

Gets the text content through HTML (), the form component displays a value that is inconsistent with the obtained value

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.