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.