我正在使用以下定价滑块 http://amirolahmad.github.io/bootstrap-pricing-slider/
我需要在statusDiv
函数中组合数字的前三个字符来重新排列数字。这样我就可以创建一个新号码。但是我在堆栈中检索这些字符。
这是代码 -
update()
它会显示$(".blinder_realstate #slider").slider({
range: "min",
animate: true,
value: 1,
min: 40000,
max: 1400000,
step: 10000,
slide: function (event, ui) {
update(1, ui.value);
}
});
update();
//changed. now with parameter
function update(slider, val) {
//changed. Now, directly take value from ui.value. if not set (initial, will use current value.)
var $amount = slider == 1 ? val : $(".blinder_realstate #amount").val();
var $duration = slider == 2 ? val : $(".blinder_realstate #duration").val();
if($amount > 1000000){
alert($amount);
var first_char = $amount[0];
alert(first_char);
var second_char = $amount[1];
var third_char = $amount[2];
var first_elem = first_char + second_char;
var second_elem = second_char + third_char;
if(second_elem >= 10){
second_elem = 0;
}
var number_format = first_elem+''+second_elem+'00000';
$amount = parseInt(number_format);
}
$total = ($amount * 1.8) / 100;
$new_total = formatNumber($total - 395);
$(".blinder_realstate #amount").val('£' + $amount);
$(".blinder_realstate #amount-label").text('£' + $new_total);
$(".blinder_realstate #duration").val($duration);
$(".blinder_realstate #duration-label").text($duration);
$(".blinder_realstate #total").val($total);
$(".blinder_realstate #total-label").text($total);
$('.blinder_realstate #slider a').html('<label><span class="glyphicon glyphicon-chevron-left"></span> £' + formatNumber($amount) + ' <span class="glyphicon glyphicon-chevron-right"></span></label>');
}
function formatNumber(num) {
return num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,")
}
值的提示,但会在alert($amount)
中显示undefined
。
提前致谢。
答案 0 :(得分:2)
您需要将金额转换为字符串。
var $amount = 1234;
var $amountStr = $amount.toString();
var first_char = $amountStr[0];
alert(first_char);
答案 1 :(得分:0)
可变数量是整数类型,它不是数组.. 所以它无效
var first_char = $amount[0];
首先在字符串中转换金额,在字符数组中转换
var charArr=String($amount).split('');
var first_char=charArr[0];
//similary for others
<强>建议强>
确保您在这里获得的内容,因此将所有内容更改为一种类型
var $amount = slider == 1 ? val : $(".blinder_realstate #amount").val();
$amount=parseInt($amount);