【问题标题】:bootstrap-progressbar jQuery plugin引导进度条 jQuery 插件
【发布时间】:2014-01-02 14:53:30
【问题描述】:

我在使用用于引导进度条的 jQuery 插件时遇到了一些问题 - http://minddust.github.io/bootstrap-progressbar/bootstrap-2.3.2.html

我想根据所选选项向用户提供进度条的预览。我面临的问题是.progressbar({...}) 仅记录选项的第一次更改,而不是之后的更改。这些值不会在后续更改中更改。

如果我选择选项"percentage",则栏上的文本显示为"40%",如果我选择"amount",则栏上的文本显示为"40/100"

所以这里的问题是,如果我首先选择 "percentage" 选项然后更改为 "amount" 仍然在按钮单击上,我看到显示的是百分比而不是数量。

我在 jQuery 代码中缺少什么?

HTML -

<div id="demo-progress-bar" class="progress">
    <div class="bar" aria-valuetransitiongoal="40">
        <span style="margin:0 10px;"></span>
    </div>
</div>

<a id="progress-bars-preview" href="#">Click to Preview</a>

<select id="progress_bar-percent" name="progress_bar-percent">
    <option value="percentage">Percentage</option>
    <option value="amount">Amount</option>
</select>

jQuery -

$('#progress-bars-preview').click(function(){
    var percent = $('#progress_bar-percent').val();
    if(percent=="percentage"){
        percent = true;
    }else{
        percent = false;
    }
    $("#demo-progress-bar .bar").progressbar({
        display_text: "fill",
        done: function(current_percentage) {
            $("#demo-progress-bar .bar span").show("slow");
        },
        use_percentage: percent
    });
});

【问题讨论】:

    标签: javascript jquery twitter-bootstrap jquery-plugins progress-bar


    【解决方案1】:
    $('#progress-bars-preview').click(function(){
        var randomValue = Math.floor(Math.random() * (100 - 10 + 1) + 10);
        var element = $("#demo-progress-bar").html();
        $("#demo-progress-bar").html("").html(element);
        $("#demo-progress-bar .bar").attr('aria-valuetransitiongoal',randomValue);
        var percent = $('#progress_bar-percent').val();
        if(percent=="percentage"){
            percent = true;
        }else{
            percent = false;
        }
        $("#demo-progress-bar .bar").progressbar({
            display_text: "fill",
            done: function(current_percentage) {
                $("#demo-progress-bar .bar span").show("slow");
            },
            use_percentage: percent
        });
    });
    

    http://jsfiddle.net/Lcp9A/3/

    【讨论】:

    • 我在 js 小提琴中看不到“点击预览”。你能再检查一下你的小提琴吗
    • 那意味着没有其他方法然后重新插入html?不过,这确实有效,谢谢!
    • @Gautam:我故意留下它,以便它可以显示进度条的变化。
    • @Gautam 我看穿了progressbar js的代码。这似乎是唯一的方法。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-30
    相关资源
    最近更新 更多