繁体   English   中英

jQuery,可以在Chrome中正常运行,但不能在Firefox和Safari中运行

[英]Jquery,working fine in Chrome, but not in Firefox and Safari

一个简单的列表排序功能。 该函数按最近日期(数据日期属性)对列表项进行排序。 在chrome中,它可以正常工作,但在Firefox和safari中,它什么也不做。 而且在firebug:s中也没有错误。

 $( document ).ready(function() {
      $('#November ul li').sort(function(a,b){
         return new Date($(a).data('date')) < new Date($(b).data('date'));
      }).each(function(){
         $('#November ul').prepend(this);
      })
   });

谁能告诉我我做错了什么? 谢谢。

得到了解决方案。 在排序之前,我需要使用toArray()方法。 但是为什么Chrome可以在不添加toArray代码的情况下正常运行,而Firefox和Safari却不能,所以我不胜其烦。 最终的代码是这样的。

$( document ).ready(function() {
  $('#December ul li').toArray().sort(function(a,b){
     return new Date($(a).data('date')) < new Date($(b).data('date'));
  }).each(function(){
  $('#December ul').prepend(this);
  })
}); 

感谢您的帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM