【问题标题】:how to use a variable in jquery ui progressbar如何在 jquery ui 进度条中使用变量
【发布时间】:2015-12-21 09:25:08
【问题描述】:

我想根据包装器div 的数据值显示progressbar

<div class="photo webdesignTag" data-progress="20">
    <div class="photo-image"></div>
    <h2>Example1</h2>
    <div class="progressbar"></div>
</div>
<div class="photo photoshopTag" data-progress="50">
    <div class="photo-image"></div>
    <h2>Example2</h2>
    <div class="progressbar"></div>
</div>
$(".photo").each(function() {
    var ProgressBarContainer = $(this).attr("data-progress");
    $(this).children("h2").html(ProgressBarContainer);
    $(this).children(".progressbar").progressbar({
        value: ProgressBarContainer
    });

谁能帮帮我?

【问题讨论】:

  • 请描述发生了什么问题。

标签: javascript jquery jquery-ui variables progress-bar


【解决方案1】:

问题是因为您使用attr() 来获取data-progress 值。这将返回一个字符串,而 value 属性需要一个整数。如果您使用data() 检索该值,它将被正确输入:

$(".photo").each(function() {
    var $el = $(this);
    var progressBarValue = $el.data("progress");
    $el.children("h2").html(progressBarValue);
    $el.children(".progressbar").progressbar({
        value: progressBarValue
    });
});

Example fiddle

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-14
    • 1970-01-01
    • 1970-01-01
    • 2012-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多