我正在尝试将默认值设置为jquery范围滑块,但它对我不起作用。我在php数组中有值,并在范围滑块中使用它们,我想选择默认值,我在下面有代码:
$sum = $wpdb->get_results("SELECT `sum_insured` FROM `{$wpdb->prefix}dh_insurance_plans_rates` WHERE `plan_id` IN (SELECT `id` FROM wp_dh_insurance_plans WHERE `product`='$product_id') GROUP BY `sum_insured` ORDER BY CAST(`sum_insured` AS DECIMAL)");
?>
var SliderValues = [<?php
$s = 0;
foreach($sum as $suma){
$s++;
echo $sumamount = $suma->sum_insured;
if($s < $wpdb->num_rows){
echo ', ';
}
} ?>];
$(function () {
$("#sum_slider").slider({
range: "min",
min: 0,
max: SliderValues.length - 1,
step: 1,
slide: function (event, ui) {
$('#coverage_amount').text(SliderValues[ui.value]);
$( "#coverage_amount" ).val( "$" + SliderValues[ui.value] );
}
});
$( "#coverage_amount" ).val( "$" + $( "#sum_slider" ).slider( "value" ) );
});
答案 0 :(得分:0)
我认为尝试更改滑块的最大值。代替 “ max:SliderValues.length-1” ...使用类似:
max: SliderValues[SliderValues.length - 1]
答案 1 :(得分:0)
我自己是这样完成的:
var selct_value = SliderValues.indexOf;
使用过
value: selct_value,