<?php
$query = "SELECT img_path FROM oc_product_color Order by color_id" ;
$result = mysql_query($query) ;
$counter = 0 ;
$z=0;
while($row = mysql_fetch_assoc($result))
{
$color[$counter] = $row['img_path'];
$counter = $counter + 1;
}
?>
<div>
<font size="4">Choose Your Product Color:</font>
</div>
<style>
label > input{ /* HIDE RADIO */
visibility: hidden;
position: absolute;
}
label > input + img{ /* IMAGE STYLES */
cursor:pointer;
border:2px solid transparent;
}
label > input:checked + img{ /* (RADIO CHECKED) IMAGE STYLES */
border:2px solid #A8813E;
}
</style>
<style>
.grow img {
height: 24px;
width: 24px;
-webkit-transition: all 1s ease;
-moz-transition: all 1s ease;
-o-transition: all 1s ease;
-ms-transition: all 1s ease;
transition: all 1s ease;
}
.grow img:hover {
width: 50px;
height: 50px;
}
</style>
<div>
<?
if($counter>0)
{
for($z=0;$z<$counter;$z++)
{
?>
<tr >
<?
if($z<$counter)
{
?>
<label class="grow pic">
<input type="radio" name="color" checked="checked" value="small" onclick = />
<img src=<?php echo $color[$z];?> width="16px" height="16px" />
</label>
<?
}
?>
</tr>
<? }
} ?>
</a></div>
</div>
<label for="color"><img src = "<?php echo $color[$z] ?>"></label>
</div>
<br>
</div>
亲爱的 Stackoverflow
我尝试获取与其关联的图像路径并显示它,但徒劳无功:
<label for="color"><img src = "<?php echo $color[$z] ?>"></label>
我是 php 新手,并且已经成功完成了这段代码
任何帮助将不胜感激
抱歉我的英语不好
感谢和问候
Akki2401
最佳答案
我不确定你在问什么,但我觉得这就是你正在寻找的!试试这个!
<div class="radio-buttons">
<input type="radio" name="rGroup" value="1" id="r1" checked="checked" />
<label class="radio-label" for="r1"></label>
<input type="radio" name="rGroup" value="2" id="r2" />
<label class="radio-label" for="r2"></label>
<input type="radio" name="rGroup" value="3" id="r3" />
<label class="radio-label" for="r3"></label>
</div>
和CSS
.radio-buttons .radio-label{
background-color:#E8C504;
display:inline-block;
width:40px;
height:40px;
border-radius:40px;
}
.radio-buttons input[type=radio]{
display:none
}
.radio-buttons input[type=radio]:checked + .radio-label{
background-color:#241009
}
关于php - 使用php中动态创建的单选按钮的onclick标签更改图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26668587/