1

I am having problems updating the ui jquery slider when a select is changed or input is changed - anyone have any ideas on the source to resolve this?

$('.application-progress').slider({
    range: "min",
    min: 0,
    max: 100,
    animate: true,
    slide: function(event, ui){
        $("#progress").html(ui.value+"%");
    }
});
$("#progress").html($(".application-progress").slider("value")+"%");

$('input').focusout(function(){
    var percentage = 0;
    $('input').each(function(){
        if($(this).val() != "")
            percentage += 10;
    });
    $("#progress").slider({value: percentage});
    $("#progress").html($(".application-progress").slider("value")+"%");
});​

我已添加到 jsfiddle:http: //jsfiddle.net/Ykx5f/1/

4

2 回答 2

0

我已经更新了你的小提琴。附加到更改事件而不是焦点/模糊。

于 2012-09-25T10:16:01.197 回答
0

这是你想要实现的吗?

$("input, select").change(function() {
    var percentage = 0;
    $('input, select').each(function() {
        if ($.trim(this.value) != "") percentage += 10;
    });
    $(".application-progress").slider("value", percentage);

    $("#progress").html(percentage + "%");
});​

演示:http: //jsfiddle.net/Ykx5f/9/


这是更新版本,它会根据输入字段的数量自动计算百分比:

$("input, select").change(function() {
    var fields = $("input, select");
    var percentage = 100 * fields.filter(function() {
        return $.trim(this.value) != "";
    }).length / fields.length;

    $(".application-progress").slider("value", percentage);
    $("#progress").html(percentage + "%");
});​

演示:http: //jsfiddle.net/Ykx5f/11/

于 2012-09-25T10:19:09.540 回答