Javascript jQuery wrapAll带变量的两个元素
我有两个变量currentSectionElement和sectionList 它们看起来像:Javascript jQuery wrapAll带变量的两个元素,javascript,jquery,html,Javascript,Jquery,Html,我有两个变量currentSectionElement和sectionList 它们看起来像: currentSectionElement = $("<div>current</div>"); sectionList = $("<div>sectionList</div>"); 我想这样显示它: <div> <div>current</div> <div>sectionList<
currentSectionElement = $("<div>current</div>");
sectionList = $("<div>sectionList</div>");
我想这样显示它:
<div>
<div>current</div>
<div>sectionList</div>
<div>
所以,我尝试了以下方法:
currentSectionElement.after(sectionList);
$(currentSectionElement, sectionList).wrapAll('<div></div>');
然而,它变成:
<div>
<div>current</div>
<div>
<div>sectionList</div>
您可以使用.add将currentSectionElement和sectionList组合成一个jQuery对象,然后使用.wrapAll
var currentSectionElement=$current;
var sectionList=$sectionList;
var newObj=currentSectionElement.addsectionList;
newObj.wrapAll.parent.appendTodocument.body;
您可以使用.add将currentSectionElement和sectionList组合成一个jQuery对象,然后使用.wrapAll
var currentSectionElement=$current;
var sectionList=$sectionList;
var newObj=currentSectionElement.addsectionList;
newObj.wrapAll.parent.appendTodocument.body;
currentSectionElement=$current;
sectionList=$sectionList;
$'body'。追加;
$'body'。查找'div'。appendcurrentSectionElement.appendsectionList
.red{color:red}
currentSectionElement=$current;
sectionList=$sectionList;
$'body'。追加;
$'body'。查找'div'。appendcurrentSectionElement.appendsectionList
.red{color:red}
$currentSectionElement,sectionList不会创建包含currentSectionElement和sectionList交集的jQuery集。为此,请使用currentSectionElement.addsectionList
如果您这样做,您的wrapAll将起作用:
currentSectionElement=$current;
sectionList=$sectionList;
currentSectionElement.addsectionList
拉帕尔先生
父母亲
.appendTodocument.body;
div{
边框:1px纯黑;
填充:4px;
}
$currentSectionElement,sectionList不会创建包含currentSectionElement和sectionList交集的jQuery集。为此,请使用currentSectionElement.addsectionList
如果您这样做,您的wrapAll将起作用:
currentSectionElement=$current;
sectionList=$sectionList;
currentSectionElement.addsectionList
拉帕尔先生
父母亲
.appendTodocument.body;
div{
边框:1px纯黑;
填充:4px;
}
谢谢但是有可能使用wrapAll吗?@CodaChang,Updated@CodaChang:是的。不一定更好,但确实如此。谢谢!但是有可能使用wrapAll吗?@CodaChang,Updated@CodaChang:是的。不一定更好,但确实如此。谢谢,很好的例子!谢谢,很好的例子!谢谢你的解释,我明白了。谢谢你的解释,我明白了。