Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
代码是:
<div class="bar"> <div class="percentage" style="width:16%; height: 59px;">This is 66% wide div</div> </div>
如您所见,此处的宽度为 16 ....我需要一种可以根据变量进行更改的方法。我有一个返回某个值的 php 查询。宽度必须是那个值。我怎样才能做到这一点?
你可以用Javascript来做。以 JQuery 为例:
$('.percentage').css({'width': x%, 'height': xpx});
或者你可以用 PHP 做到这一点:
<div class="percentage" style="width: <?php echo $width; ?>%; height: <?php echo $height; ?>px; ">This is 66% wide div</div>