Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.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代码可以在IE和Firefox中工作,而不能在Chrome中工作?_Javascript_Jquery_Html_Css_Google Chrome - Fatal编程技术网

为什么这个Javascript代码可以在IE和Firefox中工作,而不能在Chrome中工作?

为什么这个Javascript代码可以在IE和Firefox中工作,而不能在Chrome中工作?,javascript,jquery,html,css,google-chrome,Javascript,Jquery,Html,Css,Google Chrome,我正在使用这个JQuery代码对一个表进行排序。表中的行如下所示,单击按钮时,隐藏值将可见: <tr> <td>A-1</td> <td nowrap>A-2</td> <td>A-3</td> </tr> <tr> <td class="hidden">A-1</td> <

我正在使用这个JQuery代码对一个表进行排序。表中的行如下所示,单击按钮时,隐藏值将可见:

 <tr>
        <td>A-1</td>
        <td nowrap>A-2</td>
        <td>A-3</td>
 </tr>
 <tr>
        <td class="hidden">A-1</td>
        <td class="hidden" nowrap>B-1</td>
        <td class="hidden">C-1</td>
        <td class="hidden" colspan="3">
          <div id="A-row-additional-info" >
              <strong>additional info 1</strong> 
              <br/><strong>additional info 2</strong> 
              <br/><strong>additional info 3</strong> 
           </div>
        </td>
 </tr>

A-1
A-2
A-3
A-1
B-1
C-1
附加信息1

附加信息2
附加信息3
我用来排序的JS代码是:

$('th').click(function () {
    var table = $(this).parents('table').eq(0);

    var rows = table.find('tr:gt(0)').toArray().sort(comparer($(this).index()));
    this.asc = !this.asc;
    if (!this.asc) {
        rows = table.find('tr:gt(0)').toArray().sort(comparerReverse($(this).index()));
        $(this).find('a').html('&#9662');
    } else {
        $(this).find('a').html('&#9652');
    }
    for (var i = 0; i < rows.length; i++) {
        table.append(rows[i]);
    }

});
function comparer(index) {
    return function (a, b) {
        var valA;
        var valB;
        if (getCellValue(a, index).match(/^[0-9]{1,2}[\/][0-9]{1,2}[\/][0-9]{4}[ ][0-9]{1,2}[:][0-9]{1,2}[:][0-9]{1,2}[ ][a-zA-Z]{2}$/) != null)//comparing dates
        {
            valA = new Date(getCellValue(a, index)).setMilliseconds(0);
            valB = new Date(getCellValue(b, index)).setMilliseconds(0);
        }
        else {
            valA = getCellValue(a, index);
            valB = getCellValue(b, index);
        }
        return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.localeCompare(valB);
    }
}
function comparerReverse(index) {
    return function (a, b) {
        var valA;
        var valB;
        if (getCellValue(a, index).match(/^[0-9]{1,2}[\/][0-9]{1,2}[\/][0-9]{4}[ ][0-9]{1,2}[:][0-9]{1,2}[:][0-9]{1,2}[ ][a-zA-Z]{2}$/) != null)//comparing dates
        {
            valA = new Date(getCellValue(a, index)).setMilliseconds(0);
            valB = new Date(getCellValue(b, index)).setMilliseconds(0);
        }
        else {
            valA = getCellValue(a, index);
            valB = getCellValue(b, index);
        }
        return $.isNumeric(valB) && $.isNumeric(valA) ? valB - valA : valB.localeCompare(valA);
    }
}
function getCellValue(row, index) { return $(row).children('td').eq(index).html(); }
$('th')。单击(函数(){
var table=$(this).parents('table').eq(0);
var rows=table.find('tr:gt(0)').toArray().sort(比较器($(this.index()));
this.asc=!this.asc;
如果(!this.asc){
rows=table.find('tr:gt(0)').toArray().sort(comparerReverse($(this.index()));
$(this.find('a').html('▾');
}否则{
$(this.find('a').html('▴');
}
对于(变量i=0;i

这在IE和FireFox中都能很好地工作,但在Chrome中,隐藏行的排序不正确。有人知道为什么以及如何解决这个问题吗

您是否已在Chrome中检查开发人员控制台中的错误和警告?您是否可以添加完整的相关HTML,包括
按钮
th
,以便创建实时页面?否则,人们必须在考虑v8引擎的情况下通读整个代码:)检查
localeCompare
method。对于Chrome,它可以返回与Firefox或IE不同的结果。@Danielallelangdon是的,它没有抱怨任何事情,它只是对隐藏的ROE进行排序incorrectly@DmitriyLoskutov为什么chrome运行的JS与IE/FireFox不同?