jQuery function doesn't work on Safari

萝らか妹 提交于 2020-02-02 05:59:05

问题


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.

What's the reason?

The code (and a fiddle version):

  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));
            }
  });

回答1:


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

solution is here : fiddle correction

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


来源:https://stackoverflow.com/questions/15881098/jquery-function-doesnt-work-on-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!