开发者

Assigning a CSS Style to the width prooperty from an array does not work (JQUERY)

When I try to update the width property of the css with a value from the array (a percentage value) 开发者_StackOverflowand assign it to the .css() property of my object it will not change the width, but if I enter it directly then it works:

function updateCurrentAssetUploadProgressBox() {

var activeWorkflows = new Array();

activeWorkflows[0] = "15"; //progress percentage
activeWorkflows[1] = "MyTestAsset.jpg"; //asset name

var percentComplete = activeWorkflows[0] + "%"; // THIS WILL NOT WORK

$('#progressBox #metaAndLinksRow #itemName').html(activeWorkflows[1]);
//$('#progressBox #progressRow #progressBar').css('width', 'percentComplete');    // DOES NOT WORK
$('#progressBox #progressRow #progressBar').css('width', '15%');    // WORKS FINE

}

Thank you.


No quotes. You're passing 'percentComplete' as a string. Remove the quotes in the argument:

function updateCurrentAssetUploadProgressBox() {

    var activeWorkflows = new Array();

    activeWorkflows[0] = 15; //progress percentage (INT should be unquoted)
    activeWorkflows[1] = "MyTestAsset.jpg"; //asset name

    var percentComplete = activeWorkflows[0] + "%";

    $('#progressBox #metaAndLinksRow #itemName').html(activeWorkflows[1]);
    $('#progressBox #progressRow #progressBar').css('width', percentComplete); // Pass as a variable, unquoted

}


Replace:

$('#progressBox #progressRow #progressBar').css('width', 'percentComplete');

with:

$('#progressBox #progressRow #progressBar').css('width', percentComplete);


Remove the quotes around percentComplete.

Change:

$('#progressBox #progressRow #progressBar').css('width', 'percentComplete'); 

to

$('#progressBox #progressRow #progressBar').css('width', percentComplete); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜