滑块现在更新选择值 获取选择值来更新滑块值?
我创建了一个滑动条来确定用户想要下载的最大字节数。该滑块连接到一个选择框。当滑块沿线移动时,它会更新选择框中的值。但是,当您从选择框中选择一个值时,它不会更新滑块的值。我如何让它双向更新?
JavaScript
$(function() {
var select = $( "#camlogbytes");
var slider = $( " <div id='slider'></div>").insertAfter(select).slider({
min: 1,
max: 6,
step: 1,
value: select[0].selectedIndex + 1,
slide: function(event, ui) {
select[0].selectedIndex = ui.value - 1;
}
});
$("camlogbytes").change(function() {
slider.slider("value", this.selectedIndex + 1);
});
});
HTML
<tr>
<td class="column1">Max number of bytes per Camera Log:</td>
<td id="sliderbytes">
<select name="camlogbytes" id="camlogbytes">
<option value="0"selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
</tr>
I have a created a slide bar to determine the max number of bytes that a user wants to download. This slider is connected to a select box. As the slider moves along the line, it updates the value in the select box. However, when you chose a value from the select box it does not update the value of the slider. How do i get it to update both ways??
JavaScript
$(function() {
var select = $( "#camlogbytes");
var slider = $( " <div id='slider'></div>").insertAfter(select).slider({
min: 1,
max: 6,
step: 1,
value: select[0].selectedIndex + 1,
slide: function(event, ui) {
select[0].selectedIndex = ui.value - 1;
}
});
$("camlogbytes").change(function() {
slider.slider("value", this.selectedIndex + 1);
});
});
HTML
<tr>
<td class="column1">Max number of bytes per Camera Log:</td>
<td id="sliderbytes">
<select name="camlogbytes" id="camlogbytes">
<option value="0"selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
</tr>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你会踢自己的,你错过了选择器开头的#:
You will kick yourself, you missed the # at the start of the selector here: