开发者

What is the purpose of jQuery clean and cleanData methods?

jQuery has clean and cleanData methods. What i开发者_如何学编程s the purpose of jQuery clean and cleanData methods?


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().


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜