我正在通过 head first jquery 工作,并且我正在处理 jquery ui 的一章。具体来说,该示例正在浏览一个 jquery 滑块,该滑块在滑块上方显示该滑块的值。截图: http: //i.imgur.com/ahRRy.png ? 1 但是,我很难理解代码:
的HTML:
<h3>Distance from Creature (in ft.):</h3>
<input type="text" id="distance" class="just_display" name="creature_distance" readonly="readonly"/>
<div id="slide_dist"></div>
<h3>Creature Weight (in lbs.):</h3>
<input type="text" id="weight" class="just_display" name="creature_weight" readonly="readonly"/>
<div id="slide_weight"></div>
<h3>Creature Height (in ft.):</h3>
<input type="text" id="height" class="just_display" name="creature_height" readonly="readonly"/>
<div id="slide_height"></div>
查询:
//3a. slide_dist
$( "#slide_dist" ).slider({
value:0,
min: 0,
max: 500,
step: 10,
slide: function( event, ui ) {
$( "#distance" ).val( ui.value);
}
});
$( "#distance" ).val( $( "#slide_dist" ).slider( "value" ));
//3b. slide_weight
$( "#slide_weight" ).slider({
value:0,
min: 0,
max: 5000,
step: 5,
slide: function( event, ui ) {
$( "#weight" ).val( ui.value);
}
});
$( "#weight" ).val( $( "#slide_weight" ).slider( "value" ));
//3c. slide_height
$( "#slide_height" ).slider({
value:0,
min: 0,
max: 20,
step: 1,
slide: function( event, ui ) {
$( "#height" ).val( ui.value);
}
});
$( "#height" ).val( $( "#slide_height" ).slider( "value" ));
我对滑块方法中的幻灯片参数感到非常困惑:
slide: function( event, ui ) {
$( "#height" ).val( ui.value);
}
据我所知,这是更改滑块上方的值以匹配滑块的值。但是,如果是这种情况,那么滑块方法后面的行会做什么:
$( "#height" ).val( $( "#slide_height" ).slider( "value" ));
这些线不是在做同样的事情吗?任何和所有输入将不胜感激。