Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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
jQuery函数故障_Jquery_Function - Fatal编程技术网

jQuery函数故障

jQuery函数故障,jquery,function,Jquery,Function,我试图制作一个脚本,将容器中的元素放入列中。在我进入第4栏之前,脚本工作正常。我看不出我错在哪里。这是代码,还有 var container='.bar', children=$(容器).children().length, 列=4, 宽度=$(容器).width()/列-20; 函数列生成器(值){ var i=1, x=数学单元(值/列), z=数学四舍五入(值/列), y=''; $(container.children().slice(0,x).wrapAll(y); while(i1)

我试图制作一个脚本,将容器中的元素放入列中。在我进入第4栏之前,脚本工作正常。我看不出我错在哪里。这是代码,还有

var container='.bar',
children=$(容器).children().length,
列=4,
宽度=$(容器).width()/列-20;
函数列生成器(值){
var i=1,
x=数学单元(值/列),
z=数学四舍五入(值/列),
y='';
$(container.children().slice(0,x).wrapAll(y);
while(i1){
$(container.children().slice(i,x+i*i).wrapAll(y);
i++;
}
否则{
$(container.children().slice(i,x+i).wrapAll(y);
i++;
}
}
}
$(函数(){
变量容器='.bar',
children=$(容器).children().length,
列=4,
宽度=$(容器).width()/列-20;
函数列生成器(值){
var i=0,
x=数学单元(值/列),
z=数学四舍五入(值/列),
y='';
而(i<列){
$(容器).children(':not(“div.column”)).slice(0,x).wrapAll(y);
i++;
}
}
专栏作家(儿童);
$(容器)。追加(“”);
$('.column')。宽度(width);
});
此外,更改您的测试数据,使其在每次Lorum或DUI后都包含一个数字。否则,代码可能看起来像在工作,但实际上并非如此


这项技术也适用于任意数量的列(而不仅仅是4列)。

如果你停止命名变量
x
y
z
,问题可能会更容易出现。我想我是把问题弄得太复杂了。谢谢你的帮助。
var container = '.bar',
    children = $(container).children().length,
    column = 4,
    width = $(container).width() / column - 20;

function columnizer(value) {

    var i = 1,
        x = Math.ceil(value / column),
        z = Math.round(value / column),
        y = '<div class="column" />';

    $(container).children().slice(0, x).wrapAll(y);

    while (i < column) {
        if (value % 2 === 0 && z === 1 ) {
            $(container).children().slice(i, x * i).wrapAll(y);
            i++;
        }
        else if (value % 2 === 0 && z > 1) {                
            $(container).children().slice(i, x + i * i).wrapAll(y);
            i++;            
        }
        else {
            $(container).children().slice(i, x + i).wrapAll(y);
            i++;
        }
    }
}
$(function() {

var container = '.bar',
    children = $(container).children().length,
    column = 4,
    width = $(container).width() / column - 20;

function columnizer(value) {
    var i = 0,
        x = Math.ceil(value / column),
        z = Math.round(value / column),
                y = '<div class="column" />';

    while (i < column ) {   
        $(container).children(':not("div.column")').slice(0, x).wrapAll(y);
        i++;
        }
}

columnizer(children);

$(container).append("<div class='clear'></div>");

$('.column').width(width);

});