Jquery dynamically replaces the div content and dynamically displays the content, jquerydiv

Source: Internet
Author: User

Jquery dynamically replaces the div content and dynamically displays the content, jquerydiv

This article describes how Jquery dynamically replaces div content and dynamically displays it. 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 the div through ajax in the foreground:
Copy codeThe 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 display, it is found that the content of the html string is directly displayed in the div, And the html in the string is not parsed. After data query
The. text of jquery div adds content in the form of text, displaying specific text ....
To dynamically add parsed html content, use the. ppend method of jquer div.

2. Correct Solution:
Copy codeThe 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:

Div. append method // Add Html content for dynamic Parsing
Div Text: displays the loaded Text without Parsing

I hope this article will help you with jQuery programming.

Related Article

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.