2014-05-11 3 views
1

이전에 이미 알고 있었지만 어떤 이유로 작동하지 않습니다. JS에서 변수 (너비)가 있고 CSS를 반영해야합니다. 그래서 여기에 내가 $('.top').css('width', bad);을 사용하고 있지만, 어떤 이유로 작동하지 않는 것 같습니다. 나는 $('.top').css('width', '50%');이 잘 작동한다는 것을 알고 있습니다.변수를 사용하여 스타일 변경

여기에 내 코드

countMissing(); 

function countMissing() { 

//Get total inputs 
console.log("Total inputs " + form.getElementsByTagName('input').length); 
//Divide by complete inputs out of 100% and get percent 
console.log("The percentage is " + 100/form.getElementsByTagName('input').length + "%"); 

//Check 
var cback = function() { 
    bad = 0; 
    $('.form :text').each(function (i, e) { 
     if ($.trim($(e).val()) == "") bad++; 


    }); 
    if (bad > 0) $('.congrats').css("display", "block").text(bad + ' missing'); 
    else $('.congrats').hide(); 
} 
$(document).delegate('.form :text', 'focus', cback); 
$(document).delegate('.form :text', 'keyup', cback); 
$('.top').css('width',bad, '%'); 

} 

모든 아이디어의 모든입니까?

답변

2
$('.top').css('width',bad, '%'); 

해야

$('.top').css('width', bad + '%');