Home > Web Front-end > JS Tutorial > Solution to JQuery's html (data) method and <script>script block_jquery

Solution to JQuery's html (data) method and <script>script block_jquery

WBOY
Release: 2016-05-16 18:32:43
Original
892 people have browsed it

“I just noticed today that the HTML returned by the jQuery(...).html() method will filter out all <script> blocks, but sometimes, especially in AJAX applications, it is often necessary to retain the <script> in the HTML. Block, such as partial update of content containing scripts. At this time, do not use html() to read and write HTML. You should still use elem.innerHTML. I wasted an hour today because of this problem, so I would like to remind everyone. ” <br><br> After testing, it was found that the jQuery(...).html() method of the new version (after 1.3.2, the previous version has not been tested) no longer has this problem (the html() method is a The operation of reading Dom element data), but when using the html (data) method to write data to the Dom element and the data parameter contains a script script, another abnormal phenomenon occurs: perform the above operation under the Firefox (I use 3.6) browser , the script script in the data parameter will run automatically, causing page corruption, exceptions and other errors. For example, the problem I encountered is: when there is a document.write method in the script, after the html (data) operation is completed, the original page of the entire page is Some DOM elements disappeared, leaving only the execution result of the document.write() method, which caused the page to break. The specific reason is to be discussed. In the end, the problem was solved by using elem.innerHTML=data, which is hereby marked.</script>

Related labels:
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