JQuery's html (data) method and & lt; script & gt; script block solution _ jquery
Source: Internet
Author: User
When using Jquery's html (data) method to write data to Dom elements, the following problem occurs: when the data parameter contains a script block, html (data) the execution result of the method is inconsistent with the expectation. The HTML returned by the jquery(...).html () method will filter out all the script blocks, but sometimes, especially in AJAX applications, it is often necessary to retain the "script" Block in HTML. For example, to partially update the content containing the script, do not use html () to read and write HTML, or use elem honestly. innerHTML. I am sorry for the waste of one hour for this problem ."
After the test, it is found that the jquery(..).html () method that has not been verified by the new statement (1.3.2does not exist. (The html () method is an operation to read Dom element data) method when writing data to the Dom element and the data parameter contains the script, an exception occurs: execute the above operation in the Firefox (My 3.6) browser, the script in the data parameter runs automatically, causing errors such as page breaks and exceptions. For example, my problem is: there is a document in the script. after the html (data) operation is executed, the original dom elements of the entire page disappear, leaving only document. the execution result of the write () method causes a page breakdown. The specific reason is to be discussed, and elem is still used. the innerHTML = data method solves this problem and is marked here.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.