最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to add an image to select option in HTML with PHP? - Stack Overflow

programmeradmin2浏览0评论

I want to add an image in select option in HTML with PHP.

The image is first fetched from a database.

echo '<option value='.$ifet['productimage'].'><img src='.$ifet['productimage'].'/></option>'; 

I want to add an image in select option in HTML with PHP.

The image is first fetched from a database.

echo '<option value='.$ifet['productimage'].'><img src='.$ifet['productimage'].'/></option>'; 
Share Improve this question edited Mar 12, 2014 at 7:56 dnl-blkv 2,1281 gold badge17 silver badges23 bronze badges asked Mar 12, 2014 at 7:49 user3386779user3386779 7,21521 gold badges73 silver badges141 bronze badges 3
  • I get blank option in select box using <img src=> – user3386779 Commented Mar 12, 2014 at 7:51
  • see stackoverflow./a/2966006/1501051 – عثمان غني Commented Mar 12, 2014 at 7:53
  • Possible duplicate of How to add a images in select list – Kevin Brown-Silva Commented Jan 1, 2017 at 17:23
Add a ment  | 

3 Answers 3

Reset to default 2

images don't work in select infact any type of CSS is not supported in select except line-height and border you can use jquery:

here is a demo: http://designwithpc./Plugins/ddSlick#demo

To add images in a select list you'll have to add them as a background-image.

<select>
    <option value='displayvalue' style='background-image:url(".print $ifet['productimage'].");'></option>
</select>

or use it as CSS

select option[value='displayvalue']
{background-image:url(".print $ifet['productimage'].");}

Try this

<option value="<?=$ifet['productimage']?>"><img src="<?=$ifet['productimage']?>" /></option>

OR

<option value="<?php echo $ifet['productimage']; ?>"><img src="<?php echo $ifet['productimage']; ?>" /></option>
发布评论

评论列表(0)

  1. 暂无评论