Nei*_*own 2 jquery method-chaining
只是我发现下面的代码本质上是倒退的吗?
我正在使用此帖子作为参考.
// create the inner div
var $inner = $("<div>inner</div>")
// append it to a new outer div
.appendTo("<div>outer</div>")
// next change the jQuery chain to the "outer" div
.parent()
// append the outer div to the body
.appendTo("body")
// finally, go back to the last destructive command,
// giving us back a pointer to the "inner" div
.end();
Run Code Online (Sandbox Code Playgroud)
我最初的方法是抓住身体,然后在身体外面附上一个外层,然后在内部附加一个内部.
接近它然后跳过层次结构,parent ()
只是让我觉得有点好奇......
你也可以用另一种方式做到这一点:
$('body').append('<div>outer</div>').append('<div>inner<div>');
Run Code Online (Sandbox Code Playgroud)
但这会让你离开 body
最终inner
你需要:
$('body').append('<div>outer</div>').append('<div>inner<div>')
.find('div:contains(inner)');
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
483 次 |
最近记录: |