jquery操作樣式時(shí)什么時(shí)候都要加 "px"?引號(hào)什么時(shí)候用?請看帶下劃線的代碼
if(board[i][j] == 0){
theNumberCell.css("width","0px");
theNumberCell.css("height","0px");
theNumberCell.css("top",getPosTop(i,j)+cellSideLength/2);
theNumberCell.css("left",getPosLeft(i,j)+cellSideLength/2);
}
else{
theNumberCell.css("width",cellSideLength);
theNumberCell.css("height",cellSideLength);
theNumberCell.css("top",getPosTop(i,j));
theNumberCell.css("left",getPosLeft(i,j));
theNumberCell.css("background-color",getNumberBackgroundColor(board[i][j]));
theNumberCell.css("color",getNumberColor(board[i][j]));
theNumberCell.text(getNumberText(board[i][j]));
}
hasConflicted[i][j] = false;
}
$(".number-cell").css("line-height",cellSideLength+"px");
$(".number-cell").css("font-size",0.6*cellSideLength+"px");
2017-03-26
這個(gè)我也有疑問,本站jquery教程里面講的是,css的值為數(shù)字的時(shí)候,會(huì)自動(dòng)把數(shù)字轉(zhuǎn)換為字符串并在后面加上“px”。所以加不加“px”都是可以的。但是我不明白為什么最后面font-size不加px就沒事但line-heignt不加px就會(huì)失敗。希望有高手能回答
2016-08-26
值就用px.變量就不加了,變量加了就是字符串了呀