how to pass values from range slider to jquery in html

问题描述 投票:0回答:1
javascript jquery ajax input range
1个回答
0
投票

要从范围滑块获取值并将其传递给 jQuery,您可以使用 oninput 事件将事件侦听器添加到滑块元素:

function filterProducts() {
  var myCheckboxes = new Array();
  $("input[name='types[]']:checked").each(function() {
    myCheckboxes.push($(this).val());
  });
  var minPrice = $('.tm-rangeslider').data('cur_min');
  var maxPrice = $('.tm-rangeslider').data('cur_max');

  $.ajax({
    url: '<?php echo base_url()?>homecontroller/filterpt',
    type: 'POST',
    data: {
      id: <?=$idz?>,
      types: myCheckboxes,
      minPrice: minPrice,
      maxPrice: maxPrice
    },
    error: function() {
      alert('Something is wrong');
    },
    success: function(data) {
      var count = $('.myth').length;

      $('#marble').html(data);
      $('#count').html(count);
    }
  });
}

$(document).ready(function() {
  $('[name="types[]"]').click(function() {
    filterProducts();
  });

  // add event listener to range slider
  $('.tm-rangeslider').on('input', function() {
    filterProducts();
  });
 });
© www.soinside.com 2019 - 2024. All rights reserved.