热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

jQueryuislidermax-value问题-jQueryuislidermax-valueProblem

ImnewtojQuery-uiandhavingaprobleminitializingajquery-ui-slider.Imtryingtocreateasl

I'm new to jQuery-ui and having a problem initializing a jquery-ui-slider. I'm trying to create a slider having min and max values.

我是jQuery-ui的新手,在初始化jquery-ui-slider时遇到了问题。我正在尝试创建一个具有最小值和最大值的滑块。

The slider should only have one handle, which should be initialized at some value, but somehow it is always set to max. I have however a span element in which I write the actual value of the slider and the value in this span is initialize correctly.

滑块应该只有一个手柄,应该初始化一些值,但不知何故它总是设置为最大值。我有一个span元素,我在其中写入滑块的实际值,并且此范围中的值正确初始化。

I initiate the slider as follows:

我按如下方式启动滑块:

jQuery("#slider-range-min").slider({
    range: "min",
    min: 3,
    slide: function( event, ui ) {
        jQuery("#length").text(ui.value);
    }
});

The dialog in which the slider is embedded is initiated like this:

嵌入滑块的对话框启动如下:

jQuery(".config_length").live('dblclick',function() {
    jQuery("#length-form").find("input[name=referer]").val(this.id);
    var max = jQuery(this).find("input[name$='_param']").val();
    var value = jQuery(this).find("input[name$='_value']").val();
    jQuery("#slider-range-min").slider("option","max", max);
    jQuery("#slider-range-min").slider("option","value", value);
    jQuery("#length").text(value);
    jQuery("#length-form").dialog("open");
});

'#slider-range-min' is the id of the slider, '#length-form' is the id of the dialog and '#length' the id of the span. Both variables 'max' and 'value' have the correct values (controlled with Firebug).

'#slider-range-min'是滑块的id,'#length-form'是对话框的id,'#length'是span的id。变量'max'和'value'都具有正确的值(由Firebug控制)。

If for example 'max' is set to 250 and 'value' to 100, the value in the span would be 100, the handle on the slider would be at the right-most position (which should be 250?), but as soon as I click on the handle the value in the span will change to 249.

例如,如果'max'设置为250而'value'设置为100,则span中的值将为100,滑块上的句柄将位于最右侧位置(应该是250?),但是要尽快当我点击手柄时,跨度中的值将变为249。

Edit

The Problem only occurs when the 'max' value is bigger then 100 (which is the default value for the max). Moreover it seems that order in which I set 'max' and 'value' also seems to influence the behaviour.

只有当'max'值大于100(这是max的默认值)时才会出现问题。此外,似乎我设置'max'和'value'的顺序似乎也影响了行为。

What am I doing wrong?

我究竟做错了什么?

2 个解决方案

#1


1  

I found a way to make it work, but I don't think it should be necessary to do it this way:

我找到了一种让它工作的方法,但我不认为有必要这样做:

    jQuery("config_length").live('dblclick',function() {
    jQuery("#length-form").find("input[name=referer]").val(this.id);
    var max = jQuery(this).find("input[name$='_param']").val();
    var value = jQuery(this).find("input[name$='_value']").val();
    if (max > 100) {
        jQuery("#slider-range-min").slider("option", "value", value).slider("option","max", max);
    } else {
        jQuery("#slider-range-min").slider("option","max", max).slider("option", "value", value);
    }
    jQuery("#length").text(value);
    jQuery("#length-form").dialog("open");
});

Even though it works now, I would like to know if there is no 'right' way to do it.

即使它现在有效,我想知道是否没有'正确'的方法来做到这一点。

#2


0  

Actually when you are passing an object to "option" method os slider (second code snippet) it overwrites existing values, meaning all your initial options are nulls if not repeated in the new options object. Beside that "value" option is semantically affiliated to the initial value, if you are changing runtime value you have to use "value" method

实际上,当您将对象传递给“选项”方法os滑块(第二个代码片段)时,它会覆盖现有值,这意味着如果不在新选项对象中重复,则所有初始选项都为空。除了“value”选项在语义上附属于初始值,如果要更改运行时值,则必须使用“value”方法

instead of

代替

jQuery("#slider-range-min").slider("option",{
        max: max,
        value: value
    })

use

使用

jQuery("#slider-range-min").slider("option","max", max).slider("value", value);

推荐阅读
author-avatar
tha1es
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有