-1

我有这个滑块的代码并且可以工作,但我需要滑块显示我在 SQL 表中的动态值(数字和字母数字)。出于这个原因,我不能把像这里这样的静态值放在min,maxstep. 我该怎么做才能在那里显示我的表的值?

<script>
    $("#slider").slider({
        value:100,
        //MIN ANSWER INPUT VALUE ??? AND WITH MAX THE SAME
        min: 0,
        max: 500,
        step: 50,
        slide: function(event, ui) {
            $( "#amount" ).val( "$" + ui.value );
        }
    });
    $("#amount").val("$" + $("#slider").slider("value"));
});
</script>

<p>
    <label for="amount"><?php echo $row_questionset['QuestionValue']; ?>< /label>
    <input type="text" id="amount" style="border: 0; color: #f6931f; font-weight: bold;" />
</p>
<div id="slider"></div>     
4

1 回答 1

0

你可以做这样的事情。

<?php 
//get the values from the database here and set them to variables.
$minValue = 1;
$maxValue = 4;
$stepValue = 2;
?>
<html>
<script>
var minValue = <?php echo $minValue; ?> ;
var maxValue = <?php echo $maxValue; ?>;
var stepValue = <?php echo $stepValue; ?>;//if a string value, put <?php echo $stepValue; ?> inside quotes.
$( "#slider" ).slider({
                    value:100,//MIN ANSWER INPUT VALUE ??? AND WITH MAX THE SAME
                    min: minValue,
                    max: maxValue,
                    step: stepValue,
                    slide: function( event, ui ) {
                        $( "#amount" ).val( "$" + ui.value );
                    }
                });
$( "#amount" ).val( "$" + $( "#slider" ).slider( "value" ) );
</script>

<p>
<label for="amount"><?php echo $row_questionset['QuestionValue']; ?></label>
<input type="text" id="amount" style="border: 0; color: #f6931f; font-weight: bold;" />
</p>

<div id="slider">

</div>
</html>
于 2012-12-12T13:05:07.773 回答