Home > Web Front-end > JS Tutorial > body text

How to dynamically replace div content and display dynamically with Jquery

PHPz
Release: 2018-09-29 16:05:27
Original
1858 people have browsed it

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);
});
Copy after login

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);
});
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!