更改jQuery移动滑块的值

更改jQuery移动滑块的值

本文介绍了更改jQuery移动滑块的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据按钮的单击来重置或更改jQuery滑块的值,但是没有运气.我在做什么错了?

I am trying to reset or change the value of a jQuery slider based on the clicking of a button but to no luck. What am I doing wrong?

http://jsfiddle.net/yXXVr/

<input class="ui-hidden-accessible" type="range" name="slider1" id="slider1" value="50" min="0" max="100" animate="true" />
<br/>
<br>
<input class="ui-hidden-accessible" type="range" name="slider2" id="slider2" value="50" min="0" max="100" animate="true" />
<br/>
<input type="button" data-theme="a" id="go-back" value="Done"></input>

$('#go-back').click(function () {
    $("#slider1").val(50).refresh();
}

推荐答案

jsFiddle中存在一些问题.有一些语法错误,还有为完成"按钮定义的额外单击处理程序.

There were a few things wrong with what you had in your jsFiddle. There were a few syntax errors, as well as an extra click handler defined for the Done button.

<input class="ui-hidden-accessible" data-track-theme="b" data-theme="a" type="range" name="slider1" id="slider1" value="50" min="0" max="100" animate="true" />
<br/>
<br>
<input class="ui-hidden-accessible" data-track-theme="b" data-theme="a" type="range" name="slider2" id="slider2" value="50" min="0" max="100" animate="true" />
<br/>
<input type="button" data-theme="a" id="go-back" value="Done" ></input>

然后在JS中,您缺少右括号&分号,以及调用.refresh()而不是.slider("refresh")

Then in the JS, you were missing a closing parenthesis & semicolon at the very end, as well as calling .refresh() instead of .slider("refresh")

$('#go-back').click(function () {
    debugger;
    $("#slider1").val(50).slider("refresh");
});

查看此更新的小提琴以获取可用的示例.

Check out this updated fiddle for a working sample.

http://jsfiddle.net/yXXVr/2/

这篇关于更改jQuery移动滑块的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 23:57