我知道以前有人这样做过,但由于某些原因它行不通。我在 JS 中有一个变量(宽度),需要它来反射(reflect) 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, '%');
}
有什么想法吗?
最佳答案
$('.top').css('width',bad, '%');
应该是
$('.top').css('width', bad + '%');
关于javascript - 使用变量更改样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23588105/