-1
我試圖使用div標籤和寬度%來顯示進度條。在php中使用樣式標記回顯div標籤以顯示進度條
的代碼看起來是這樣的:
$width = $density;
$width = sprintf ("%d\n",$width);
echo '<div style="width:200px;height:15px;background:#FFFFFF;border:1px
solid #000000;">'; // displays the outer white bar
echo '<div style="width: $width%; height:15px;background:#0033FF;font-size:8px;line-height:8px;">'; // displays the colored bar according to the value of width
echo "</div>";
echo "</div>";
問題:代碼未服用變量$寬度在第二回波。
它只是顯示一個0%的數字(空白欄,即使當$ width爲100時),或者當$ width的值爲0時顯示一個完整的彩色欄。(我回顯了這些值以便與欄進行交叉檢查顯示)
當我給出一個百分比硬的數字時,酒吧的作品,並顯示在彩色區域%。
...我已經尋找修復並嘗試各種組合,如使用:
echo '<div style="width: '. $width. ' %; [rest of tags here]
我做錯什麼了嗎?是否有一種特殊的方式將樣式標記中的變量與%符號一起傳遞?
從'sprintf'刪除'\ N'。 – hjpotter92