Jquery UI滑块手柄上次保存的值 [英] Jquery UI slider handle on last saved value

查看:107
本文介绍了Jquery UI滑块手柄上次保存的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何设置句柄从上次保存的值开始?由于某种原因,它总是在最后一个位置。我使用数据库中的值设置我的开始位置和最大值,但这里是一个工作示例:

How can I set the handle to start on the last saved value? For some reason it's always in the last position. I'm setting my start position and max value using values from the database but here is a working example:

http://jsfiddle.net/hcKwQ/ 幻灯片应该从5开始,而不是10的最大值..请帮助我不知道我做错了什么。

http://jsfiddle.net/hcKwQ/ Slide should start at 5, not 10 the max value.. Please help I don't know what I'm doing wrong.

脚本:

$(function() {
    $( "#slider" ).slider({
        range: "min",
        value: $("input[name='shirts']").val(),
        min: 1,
        max: $("input[name='max_shirts']").val(),
        step: 1,
        slide: function( event, ui ) {
            $( "#amount" ).text( ui.value );
        },
        stop: function( event, ui ) {
            $( "#shirts" ).val( ui.value );
        }
    });
});

HTML

<div id="slider"></div>
<div class="amount" id="amount"></div>

<input type="hidden" name="shirts" value="<?php echo $shirts; ?>" id="shirts">

<input type="hidden" name="max_shirts" value="<?php echo $max_shirts; ?>" id="max_shirts">


推荐答案

将值选项更改为:

value:parseInt($(input [name ='shirts'])。val()),

这是一个完整的演示: http://jsfiddle.net / lucuma / hcKwQ / 1 /

Here is a full demo: http://jsfiddle.net/lucuma/hcKwQ/1/

插件需要一个数字,所以你需要解析它。

The plugin is expecting a number so you need to parse it..

http://jqueryui.com/demos/slider/#option-value

这篇关于Jquery UI滑块手柄上次保存的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆