2

我有一个滑块的代码并且结构显示正确但是当我移动幻灯片时,不要在输入框“数量”内显示答案的值,出现“未定义”,我不知道为什么,因为当你检查你可以看到 div 滑块在标签 name 中有一个值。我也尝试过使用 html 标签“值”,但也没有用。我能做些什么 ?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
    <title>  Questionnaire </title>
    <meta name="Description" content="Questionnaire on business model" />
    <script src="jquery-1.8.3.js" type="text/javascript"></script>
    <script src="jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
    <script src="jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>    
    <script src="jquery-ui-1.9.2.js"></script>
    <script src="factaris.js"></script> 
    <link rel="stylesheet" href="STYLE.css" type="text/css" media="screen" />
    <script>
    jQuery(document).ready(function(){

        ///SLIDER !!!!!!!!!!!!!!!!!!!!!!!!!!!

        $( "#slider" ).slider({ 
        slide: function( event, ui ) {
            //$( "#amount" ).val( "$" + ui.value );  // show range 0-100 without ini values !!!!!
            // $( "#amount" ).val( "$" + this.value  ); //show undefined
            //   $( "#amount" ).val( "$" + 8); // show 8 all time
            $( "#amount" ).val( "$" + ui.name );    
        }
        });     
    });
    </script>
</head>
<body>
<div id="sizer">
    <form id= "formID"  name="formID" class="formular"   method="post" action= "<?= $url = "QUESTIONAREFINISHING.php"; ?>" accept-charset="utf-8">
    <div id="questionare" >
    <!--SLIDER-->   

    <?php if($row_questionset['Constructor']=="Slider"){?>
    <div>
        <label class="desc" value= "<?php $row_questionset['QuestionIDFKPK'];?>">
        <?php echo $row_questionset['QuestionValue']; ?>
        </label>
    </div>                                                          
    <?php while ($row_Answer=mysql_fetch_array($AnswersValue)){ ?>  
    <p>
        <label for="amount"><?php echo $row_questionset['QuestionValue']; ?></label>
        <input type="text" id="amount" name="amount"  />
    </p>

    <div id="slider" name="<?php echo $row_Answer['AnswerValue']; ?>" ></div>

    <?php } // End while loop ?>
    <?php } //End slider row ?> 
    <!--/SLIDER-->  
    </div>   
</form>
</div>   
</body>    
</html>
4

3 回答 3

3

要读取 jQuery UI Slider 的值,您需要在有问题的元素上调用滑块方法,并使用“值”作为参数,如下所示:

$( "#slider" ).slider( "value" );
于 2012-12-13T14:03:58.547 回答
0

with the value slider argument, if you want read the value on change the slider or/and on slide use the event methods of the slider:

function outputValue(sliderDom) {
    alert($(sliderDom).slider('value'));
};

$( "#slider" ).slider({
    //... your init
    slide: function(){
        outputValue(this);
    },
    change: function(){
        outputValue(this);
    }
});

edit

to fix you value problem try this

$('#slider').slider({
    //..
    min: 0,
    max: 100000 //or more
});
于 2012-12-13T14:43:43.087 回答
0

如果您希望 m 设置初始值,则需要在调用slider方法时设置它(使用 JS - 而不是 HTML)。

$("#slider).slider({
    max: slideMax,
    min: slideMin,
    value: slideInit,

// To set the value to the `#amount` element, use the following `slide` event
    slide: function( event, ui ) {
        $( "#amount" ).val( ui.value );    
    }
});
于 2012-12-13T15:34:41.697 回答