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

时间:2013-05-01 09:19:37

标签: javascript sorting random prestashop

出于某种原因,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");*/
    }
});

网址失败:http://piguskompiuteris.lt/6_asus 普通呈现网址:http://piguskompiuteris.lt/16-lenovo

如何解决这个问题的任何建议将不胜感激。感谢

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

可能的原因: 1)高度属性太小,不包括高度+填充+边距+边框 2)函数放置有问题(当前不在标题中)或调用它$(document).ready(function()

2 个答案:

答案 0 :(得分:0)

我检查了您的网站。并发现此解决方案使用它:

columns.height(tallestcolumn);

使用以下代码替换上述代码:

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

这对你有用。

答案 1 :(得分:0)

排序脚本有效。

修复脚本使用:

$(window).load(function(){});

而不是:

$(document).ready(function(){});

相关问题