简体   繁体   English

使用PHP中动态创建的单选按钮的onclick标记更改图像

[英]changing image using onclick tag of dynamically created radio buttons in php

<?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>

Dear Stackoverflow 亲爱的Stackoverflow

I tried to get the image path associated to it and display it but it was in vain: 我试图获取与之关联的图像路径并显示它,但是它是徒劳的:

<label for="color"><img src = "<?php echo $color[$z] ?>"></label>

I am new to php and have managed to do this piece of code 我是php的新手,并设法完成了这段代码

Any help will be appreciated 任何帮助将不胜感激

Sorry for my bad english 对不起,我的英语不好

Thanks & Regards 感谢和问候
Akki2401 Akki2401

I am not sure what you are asking but i feel this is what you are looking for! 我不确定您要问的是什么,但我觉得这就是您要寻找的! try this! 尝试这个!

<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>

and Css 和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
}

try fiddle here http://jsfiddle.net/raghuchandrasorab/qzjddx6v/ 在这里尝试小提琴http://jsfiddle.net/raghuchandrasorab/qzjddx6v/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM