无法将变量变为Jquery函数

时间:2012-09-19 15:47:49

标签: javascript jquery html jquery-ui

percent变量得到“警告”就好了。但是,当我把它放在progressbar函数中时,只是默认为零。如果我对值value: 60进行硬编码,它将起作用。如何使用percent变量?感谢。

    function updateProgress(percent)
    {
        alert(percent);
        $("#progressbar").progressbar({
            value: percent
        });
    }

3 个答案:

答案 0 :(得分:4)

问题是变量percent是一个字符串,所以将它转换为整数或更好的浮点数:

value: parseFloat(percent)

答案 1 :(得分:3)

function updateProgress (percent) {
  alert(percent);

  $("#progressbar").progressbar({
    value: parseFloat(percent)
  });
}

答案 2 :(得分:1)

您的代码看起来是正确的。试试这个:

function updateProgress(percent)
{
    var progress = {
        value: percent
    };
    alert(progress.value);
    $("#progressbar").progressbar(progress);
}