Jquery dynamic replacement of div content and dynamic display method _ jquery

Source: Internet
Author: User
This article mainly introduces Jquery's dynamic replacement of div content and its dynamic display methods. It also provides tips and precautions for dynamically replacing and displaying div content, for more information about how Jquery dynamically replaces p content and displays it, see the examples in this article. Share it with you for your reference. The specific analysis is as follows:

I. problems:

In the project, html needs to be spliced in the background and then displayed to p through ajax at the foreground:

The code is as follows:

Sys_ajaxGet ("/dynamic/default. do? Method = show ", {guid: guid}, function (json ){
// The html content can be correctly displayed here
Alert(json.html Content );
$ ("# HtmlContent" ).text(json.html Content );
Bind (json );
});

After the presentation, we found that p directly showed the html string content, and did not parse the html content. After Data Query
The. text of jquery p is added as text, displaying specific text ....
To dynamically add Parsed html content, use the. ppend method of jquer p.

2. correct solution:

The code is as follows:

AjaxGet ("/dynamic/default. do? Method = show ", {guid: guid}, function (json ){
// The html content can be correctly displayed here
Alert(json.html Content );
Var htmlContent = $ ("# htmlContent ");
HtmlContent.append(json.html Content );
Bind (json );
});

III. Summary:

P. append method // add Html content for dynamic parsing
P Text: displays the loaded Text without parsing

I hope this article will help you with jQuery programming.

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.