What is the purpose of jQuery clean and cleanData methods?

后端 未结 2 1268
春和景丽
春和景丽 2020-12-03 14:16

jQuery has clean and cleanData methods. What is the purpose of jQuery clean and cleanData methods?

相关标签:
2条回答
  • 2020-12-03 14:41

    From "Secrets of the Javascript Ninja"

    <script type="text/javascript">
         function clone() {
           var ret = this.map(function () {
             if (!jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this)) {
               var clone = this.cloneNode(true),
               container = document.createElement("div");
               container.appendChild(clone);
               return jQuery.clean([container.innerHTML])[0];
              }
              else
              return this.cloneNode(true);
              });
              var clone = ret.find("*").andSelf().each(function () {
              if (this[ expando ] !== undefined)
                 this[ expando ] = null;
              });
              return ret;
              }
    </script>
    

    "... the preceding code uses JQuery's Jquery.clean method, which converts an HTML string into a DOM structure"

    0 讨论(0)
  • 2020-12-03 14:46

    Both are internal, undocumented methods, so you should not use them or rely on their current behavior, because they might change or disappear in the future.

    That said, clean() sanitizes the markup in the document fragments that are created from the HTML strings passed to some functions (most notably to $() itself).

    cleanData() frees the data associated with elements when they disappear from the DOM, e.g. through remove(), empty(), or html().

    0 讨论(0)
提交回复
热议问题