我知道以前已经做过,但由于某种原因它不会起作用。我在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, '%');
}
有什么想法吗?
答案 0 :(得分:2)
$('.top').css('width',bad, '%');
应该是
$('.top').css('width', bad + '%');