jQuery函数在Safari上不起作用 [英] jQuery function doesn't work on Safari

查看:189
本文介绍了jQuery函数在Safari上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个功能可以按价格ASC和DESC对div进行排序.但是在Safari上不起作用. 在Firefox/Chrome上可以.

I've one function for sort div by price ASC and DESC. But it doesn't work on Safari. It's ok on Firefox/Chrome.

这是什么原因?

代码(以及小提琴版本):

  function sortByPrice(a,b){
      return $(a).find('.cicerone_price').text() > $(b).find('.cicerone_price').text();
  }

  function sortByPriceDesc(a,b){
     return $(a).find('.cicerone_price').text() < $(b).find('.cicerone_price').text();
  }

  function reorderEl(el){
      var container = $('#tabs');
      container.html('');
      el.each(function(){
          $(this).appendTo(container);
      });
  }
  $('#filter_price').change(function(){
      if ($("#filter_price option:selected").val()=='desc'){ 
          reorderEl($('.global_product').sort(sortByPriceDesc));
         } else if ($("#filter_price option:selected").val()=='asc'){ 
            reorderEl($('.global_product').sort(sortByPrice));
            }
  });

推荐答案

问题已解决,对于该解决方案,我为十进制添加了parseFloat

The problem has been solved, for the solution, i add parseFloat for decimal

解决方案在这里:小提琴校正

function sortByPrice(a,b){
    return parseFloat($(a).find('.productPriceForSorting').text()) > parseFloat($(b).find('.productPriceForSorting').text()) ? 1 : -1;
}

这篇关于jQuery函数在Safari上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆