读取价格折磨值 [英] Read Price Suffering Values
问题描述
使用ui jquery插件获得了价格范围.我想读取使用这些代码的JavaScript的最低和最高价格范围.但它不读取minamout和maxamount.如何正确读取minamount和maxamount.我想在脚本的另一个函数中使用它们.
Got the price range with the ui jquery plugin.I want to read the lowest and highest price range in javascript i used these codes.But it does not read minamout and maxamount. How can I read minamount and maxamount correctly.i want to use them in another function in script.
<div id="slider"></div>
<p> <span id="slider-value"></span></p>
<script>
const numberFormat = new Intl.NumberFormat();
$("#slider").slider(
{
range: true,
values: [1000, 4005000],
min: 1000,
max: 4005000,
step: 10000,
slide: function (event, ui) {
console.log(ui);
$("#slider-value").html(`${numberFormat.format(ui.values[0])} تومان — ${numberFormat.format(ui.values[1])}تومان`);
}
}
);
var values = $('#slider').slider('values');
$("#slider-value").html(` ${numberFormat.format(values[0])} تومان — ${numberFormat.format(values[1])}تومان`);
var minamount = $("#slider-value").html(values[0]);
var maxamount = $("#slider-value").html(values[1]);
</script>
</div>
推荐答案
您可以在滑块的slide
事件处理程序中读取最小值和最大值,并使用$( "#slider" ).slider( "option", "values" )
读取值.
You can read min and max values inside slide
event handler of the slider and use $( "#slider" ).slider( "option", "values" )
to read values.
您可以创建最小数量和最大数量值的数组并将其设置为滑块
you can create array of min amount and max amount values and set it to slider
请参见下面的代码
$(function(){
var minAmount = 1000;
var maxAmount = 4005000;
const numberFormat = new Intl.NumberFormat();
$("#slider").slider(
{
range: true,
values: [1000, 4005000],
min: 1000,
max: 4005000,
step: 10000,
slide: function (event, ui) {
var values = $( "#slider" ).slider( "option", "values" );
$('#min').html(values[0]);
$('#max').html(values[1]);
// set min and max values in variable which you can read to any other function
minAmount = values[0];
maxAmount = values[1];
}
}
);
// push min and max values and set it to slider
var min = 200000;
var max = 3100000;
var valuesArray = [min, max];
$( "#slider" ).slider( "option", "values", valuesArray );
});
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<div id="slider"></div>
<div id="min"></div>
<div id="max"></div>
这篇关于读取价格折磨值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!