Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery wrapAll带变量的两个元素_Javascript_Jquery_Html - Fatal编程技术网

Javascript jQuery wrapAll带变量的两个元素

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和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:是的。不一定更好,但确实如此。谢谢,很好的例子!谢谢,很好的例子!谢谢你的解释,我明白了。谢谢你的解释,我明白了。