【发布时间】:2015-03-31 02:41:10
【问题描述】:
我想在下面的html页面中制作:
<a href="1" class="currentvid"></a>
<a href="2"></a>
<a href="3"></a>
但是,我不想一一写出来,因为数字(1,2,3)来自$number变量,它可以超过3。
【问题讨论】:
-
然后向我们展示您当前拥有的代码
标签: php html loops for-loop echo
我想在下面的html页面中制作:
<a href="1" class="currentvid"></a>
<a href="2"></a>
<a href="3"></a>
但是,我不想一一写出来,因为数字(1,2,3)来自$number变量,它可以超过3。
【问题讨论】:
标签: php html loops for-loop echo
使用for 循环:
for ($i = 1; $i <= $number; $i++) {
echo "<a href='$i'";
if ($i == $currentvid) {
echo " class='currentvid'";
}
echo "></a>";
}
【讨论】:
试试这个:
<?php
$href="1";
for($i=1;$i<4;$i++){
if($href==$i){
echo "<a href=\"$href\" class=\"currentvid\">$i</a>";
}else{
echo "<a href=\"$href\">$i</a>";
}
}
?>
【讨论】:
$i = 1;
foreach ($number as $k)
{
if($i == 1)
{
echo "<a href=\"$href\" class=\"currentvid\">$i</a>";
}
else
{
echo "<a href=\"$href\">$i</a>";
}
}
}
【讨论】: