Home >Web Front-end >JS Tutorial >How to dynamically replace div content and display dynamically with Jquery
The example in this article describes the method of dynamically replacing div content and dynamic display with Jquery. Share it with everyone for your reference. The specific analysis is as follows:
1. Problem:
In the project, it is necessary to splice html in the background and then display it into the div through ajax in the foreground:
sys_ajaxGet("/dynamic/default.do?method=show", {guid:guid},function(json){ //这里可以正确的展示html内容 alert(json.htmlContent); $("#htmlContent").text(json.htmlContent); bind(json); });
After the display, it was found that the html string content was directly displayed in the div, and the html in it was not parsed. After data query.
The .text of jquery div adds content in the form of text, and displays the specific text....
If you want to dynamically add parsable html content, you need to use jquer div a.ppend method
2. Correct processing method:
ajaxGet("/dynamic/default.do?method=show", {guid:guid},function(json){ //这里可以正确的展示html内容 alert(json.htmlContent); var htmlContent = $("#htmlContent"); htmlContent.append(json.htmlContent); bind(json); });
3. Summary:
div .append method // Add Html content, dynamically parse
div Text: display the loaded text content, do not parse
. I hope this article will be helpful to everyone's jQuery programming. For more related tutorials, please Visit jQuery Video Tutorial!