使用jQuery克隆HTML文件很容易:
alert($("html").clone().html());
Run Code Online (Sandbox Code Playgroud)
我的目标是克隆整个程序,除了'.ignore'类的div之外,但我能做的最好只显示那些div.
// This displays the inverse of what I want: just the code to be removed
alert($("html").clone().find('.ignore').remove().html());
// Seems to have the exact same effect as above:
alert($("html").clone().find('.ignore').html());
Run Code Online (Sandbox Code Playgroud)
除了指定的div类之外,获得所有div类的最佳方法是什么?
你可以使用这个.end功能
alert($("html").clone().find('.ignore').remove().end().html());
Run Code Online (Sandbox Code Playgroud)
这里有一个工作小提琴:http://jsfiddle.net/sh99ognm/
| 归档时间: |
|
| 查看次数: |
1323 次 |
| 最近记录: |