Javascript随机无法对项目进行排序,没有错误

javascript randomly fails to sort items, no error

本文关键字:排序 有错误 项目 随机 Javascript      更新时间:2023-09-26

由于某些原因,Javascript会随机停止工作。

处理高度问题的代码:

$(document).ready(function() 
{ 
    /*setEqualHeight($("ul#product_list li"));*/
    //alert("some text");
    /*setEqual($("ul#product_list"));*/
    //var i = 2;
    //alert($('ul#product_list li:nth-child('+ (i + 2) +')').height()); //this is correct way to get value*/
    var elements = $('ul#product_list li').length; //this is correct way to get value
    /*var liekana = elements % 3;
    elements = elements - liekana;
    alert(elements);*/
    for(var i = 1; i <= elements; i = i + 3)
    {
        var first = $('ul#product_list li:nth-child('+ (i) +')').height();
        var second = $('ul#product_list li:nth-child('+ (i + 1) +')').height();
        var third = $('ul#product_list li:nth-child('+ (i + 2) +')').height();
        var tallest = 0;
        if (first > second)
            if (first > third)
            {
                tallest = first; 
            }
            else 
            {
                tallest = third;
            }
        else
            if (second > third)
            {
                tallest = second;
            }
            else
            {
                tallest = third;
            }
        $('ul#product_list li:nth-child('+ (i) +')').height(tallest);
        $('ul#product_list li:nth-child('+ (i + 1) +')').height(tallest);
        $('ul#product_list li:nth-child('+ (i + 2) +')').height(tallest);
        /*if (!third)
            alert("yra");*/
    }
});

URL: http://piguskompiuteris.lt/6_asus正常渲染URL: http://piguskompiuteris.lt/16-lenovo

对于如何解决这个问题,任何建议都将非常感谢。由于

更新2。我重写了javascript代码…我还是会得到相同的随机错误,有时网格会崩溃。我不确定原因是什么。

可能的原因:1) Height属性太小,不包括Height + padding + margin + border2)函数位置有问题(目前不在header中)或调用它$(document).ready(function()

我检查了你的网站。并找到了这个解决方案,使用它:

columns.height(tallestcolumn);

将以上代码替换为以下代码:

columns.css("min-height", tallestcolumn+" !imporatant");

排序脚本工作

修改脚本:

$(窗口).load(函数(){});

Out代替:

$(文档)时(函数(){});