Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.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 使用mootools将div环绕在其他div上_Javascript_Mootools - Fatal编程技术网

Javascript 使用mootools将div环绕在其他div上

Javascript 使用mootools将div环绕在其他div上,javascript,mootools,Javascript,Mootools,我得到了一个带有类overview的主div,在该主div中,每4个元素都应该用div包装 以下是html结构: <div class="overview"> <a class="item" href="#">Test1</a> <a class="item" href="#">Test2</a> <a class="item" href="#">Test3</a> <a c

我得到了一个带有类
overview
的主
div
,在该主div中,每4个元素都应该用
div
包装

以下是html结构:

<div class="overview">
    <a class="item" href="#">Test1</a>
    <a class="item" href="#">Test2</a>
    <a class="item" href="#">Test3</a>
    <a class="item" href="#">Test4</a>
    <a class="item" href="#">Test5</a>
    <a class="item" href="#">Test6</a>
    <a class="item" href="#">Test7</a>
    <a class="item" href="#">Test8</a>
    <a class="item" href="#">Test9</a>
    <a class="item" href="#">Test9</a>
    <a class="item" href="#">Test9</a>
    <a class="item" href="#">Test9</a>
</div>


如何使用mootools实现这一点?

很简单,只需使用mod

(function(){
    var wrapper,
        overview = document.getElement('div.overview');

    overview.getElements('a.item').each(function(a, i){
        if (i % 4 == 0){
            wrapper && overview.adopt(wrapper);
            wrapper = new Element('div');
        }
        wrapper.adopt(a);
    });

    overview.adopt(wrapper);
}());
在行动中: