尝试在选择选项列表中回显图像源 [英] Trying to echo an image source in a select option list

查看:40
本文介绍了尝试在选择选项列表中回显图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个php循环,试图在select选项标签内回显HTML图像源,如下所示:

I have a php loop where I am trying to echo a HTML image source inside the select option tag, like this:

foreach($recs as $i){
    if($i->isscripted == 1){
      $is = "<img src='greencheck.gif'>"; 
    }else{
      $is = "<img src='redbang.gif'>"; 
    }

   echo "<option value=".$i->id.">".$is."  ".$i->fullname."</option>";
}

图像未显示在选择列表中.我在循环外测试了图片标签,它显示正常.

The image is not displaying in the select list. I tested the image tag outside of the loop and it displays fine.

echo "<img src='greencheck.gif'>";

推荐答案

您不能使用纯HTML做到这一点,但是有一些解决方法:

You cannot do it using pure HTML, but there are a few workarounds:

  1. CSS背景(仅在Firefox中有效):

<select>
    <option value="volvo" style="background-image:url(images/volvo.png);">Volvo</option>
    <option value="saab"  style="background-image:url(images/saab.png);">Saab</option>
    <option value="honda" style="background-image:url(images/honda.png);">Honda</option>
    <option value="audi"  style="background-image:url(images/audi.png);">Audi</option>
</select>

  • 使用jQuery插件

    JavaScript图片下拉列表

    您是否对旧时尚下拉列表感到厌倦?试试这个新的.图像组合框.您可以在每个选项中添加一个图标.它可以与您现有的"select"元素一起使用,也可以通过JSON对象创建.

    JavaScript Image Dropdown

    Are you tired with your old fashion dropdown? Try this new one. Image combo box. You can add an icon with each option. It works with your existing "select" element or you can create by JSON object.

    http://www.queness.com/resources/images/formplugin/22.gif

    这篇关于尝试在选择选项列表中回显图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆