JQuery UI: multiple progress bar - problems to set dynamic values

杀马特。学长 韩版系。学妹 提交于 2019-12-12 10:38:12

问题


I have some progress bar (search results), which value is dynamically set on document.ready

<div class="progressbar" rel="21"></div>
<div class="progressbar" rel="36"></div>
<div class="progressbar" rel="44"></div>
<div class="progressbar" rel="58"></div>

And

$(document).ready(function () {

  $("div.progressbar").progressbar({
    value: $(this).attr("rel")
  });
});

This not seems to work. Instead, if i do value: 40, everything works, so the problem is not in the inclusion or use.

I tried with $.each too, but nothing

$("div.progressbar").each (function () {
    var element = this;

    console.log($(element).attr("rel")); //ok right value

   $(element).progressbar({
        value: $(element).attr("rel")
    });
});

Any ideas?

EDIT: This works

$("div.progressbar").each (function () {
    var element = this;

   $(element).progressbar({
        value: parseInt($(element).attr("rel"))
    });
});

回答1:


need to send a number

progressbar => object value => integer

$(element).attr("rel") = "21" => string value
parseInt($(element).attr("rel")) = 21 integer value


$(document).ready(function () {
  $("div.progressbar").progressbar({
    value: parseInt($(element).attr("rel"))
  });
});



回答2:


Have you tried using option method to modify value instead of passing it as initialization params?



来源:https://stackoverflow.com/questions/3116673/jquery-ui-multiple-progress-bar-problems-to-set-dynamic-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!