我正在尝试创建一个按钮,可以将jquery范围滑块从使用“内部值”切换为使用“外部值”,反之亦然。除了事件监听器功能之外,一切正常。我该怎么改变呢?
我的HTML:
<label for="direction" class="slider">Direction: <span class="swap-direction"></span></label>
<input id="direction" type="text" name="direction">
<div id="slider-direction"></div>
和我的jquery:
$("#slider-direction").slider({
range: true,
min: 0,
max: 359,
values: [45, 300],
step: 1,
slide: function(event, ui){
$("#direction").val(ui.values[1] + "deg tot " + ui.values[0] + "deg");
}
});
$("#direction").val($("#slider-direction").slider("values", 1) + "deg tot " + $( "#slider-direction" ).slider("values", 0 ) + "deg" );
$('#slider-direction, #slider-direction .ui-slider-range').toggleClass('ui-widget-header ui-widget-content');
$('label.slider span.swap-direction').click(function(){
$('#slider-direction, #slider-direction .ui-slider-range').toggleClass('ui-widget-header ui-widget-content');
var richtingwaardes = $("#direction").val();
var richtingwaardes = richtingwaardes.match(/\d+/g);
$("#direction").val(richtingwaardes[1] + "deg tot " + richtingwaardes[0] + "deg");
$("#slider-direction").on("slide", function(event, ui) {
$("#direction").val(ui.values[1] + "deg tot " + ui.values[0] + "deg");
});
});
除了移动滑块时使用的事件侦听器,一切正常。我希望它也可以切换。有人有想法吗?