简体   繁体   English

我如何将范围 slider 值与 pst 属性相乘,然后还与其他字段一起计算,然后显示结果?

[英]Ho do i multiply range slider value with pst attribute then also calculate with other field and then show the result?

Here is my code...这是我的代码...

<div id="estimate">
<div class="form-group">
  <div class="range-slider">
  <input class="range-slider__range form-control prc e-range" type="range" value="100" min="0" max="500" pst="3">
  <span class="range-slider__value">0</span>
</div>
</div>
<div class="form-group">
  <div class="range-slider">
  <input class="range-slider__range form-control prc e-range" type="range" value="100" min="0" max="500" pst="5">
  <span class="range-slider__value">0</span>
</div>
</div>
<div class="form-group">
    <input type="number" class="form-control prc" value="{{vl}}"/>
</div>
<div class="form-group">
    <input type="number" class="form-control prc" value="5"/>
</div>
<div class="form-group">
  <input type="checkbox" value="10" class="form-control prc">
</div>
<p id="result"></p>
</div>
<script>
estimate();

$('.form-group').on('change','.prc',estimate);

function estimate(){
  let totalSum = 0;
  $('.form-group .prc').each(function(){
    if(this.type=="checkbox" && !this.checked) return
    let inputVal = $(this).val();
    if($.isNumeric(inputVal)){
        totalSum += parseFloat(inputVal);
    }
  });
  
  $('#result').html(totalSum);
}

var rangeSlider = function(){
  var slider = $('.range-slider'),
      range = $('.range-slider__range'),
      value = $('.range-slider__value');
    
  slider.each(function(){

    value.each(function(){
      var value = $(this).prev().attr('value');
      $(this).html(value);
    });

    range.on('input', function(){
      $(this).next(value).html(this.value);
    });
  });
};

rangeSlider();
</script>

Here I wants the range slider only multiply value with pst attribute then calculate with other fields and then its show the result.. here can't use any specific id for each item... only can call by any specific class with same type input field like range.在这里,我希望范围 slider 仅将值与 pst 属性相乘,然后与其他字段计算,然后显示结果..这里不能为每个项目使用任何特定的 id ...只能由具有相同类型输入的任何特定 class 调用领域如范围。 and each range vlue should multiply with each pst value then calcualte with other fields并且每个范围值应与每个 pst 值相乘,然后与其他字段一起计算

Consider the following example.考虑以下示例。

 estimate(); $('.form-group').on('change', '.prc', estimate); function estimate() { var totalSum = 0, add, v, m; $('.form-group.prc').each(function(i, el) { if ($(el).is(":checkbox") &&.$(el):is(";checked")) { add = 0. } else if ($(el).hasClass("e-range")) { v = parseInt($(el);val()). m = parseInt($(el);attr("pst")); add = (v * m). } else { add = parseFloat($(el);val()); } totalSum += add; }). $('#result');html(totalSum). } function rangeSlider() { var slider = $(',range-slider'). range = $(',range-slider__range'). value = $(';range-slider__value'). slider.each(function() { value.each(function() { var value = $(this).prev();attr('value'). $(this);html(value); }). range,on('input'. function() { $(this).next(value).html(this;value); }); }); }; rangeSlider();
 <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script> <div id="estimate"> <div class="form-group"> <div class="range-slider"> <input class="range-slider__range form-control prc e-range" type="range" value="100" min="0" max="500" pst="3"> <span class="range-slider__value">0</span> </div> </div> <div class="form-group"> <div class="range-slider"> <input class="range-slider__range form-control prc e-range" type="range" value="100" min="0" max="500" pst="5"> <span class="range-slider__value">0</span> </div> </div> <div class="form-group"> <input type="number" class="form-control prc" value="0" /> </div> <div class="form-group"> <input type="number" class="form-control prc" value="5" /> </div> <div class="form-group form-check"> <input type="checkbox" value="10" class="form-check-input form-control prc"> <label class="form-check-label">10</label> </div> <p id="result"></p> </div>

If you need to get the attribute of an element, use .attr() .如果需要获取元素的属性,请使用.attr()

See more:看更多:

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

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