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.