select option项目带图片

http://www.corange.cn//uploadfiles/120_72973.jpg


演示地址:http://www.corange.cn/demo/3826/index.html
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="jquery.customselect.js"></script>
<title>Custom select boxes with icons</title>
<style type="text/css">
#iconselect {
background: url(select-bg.gif) no-repeat;
height: 25px;
width: 250px;
font: 13px Arial, Helvetica, sans-serif;
padding-left: 15px;
padding-top: 4px;
}
.selectitems {
width: 230px;
height: 25px;
border-bottom: dashed 1px #ddd;
padding-left: 10px;
padding-top: 2px;
}
.selectitems span {
margin-left: 5px;
}
#iconselectholder {
width: 250px;
overflow: auto;
display: none;
position: absolute;
background-color:#fff5ec;
}
.hoverclass{
background-color: #fff;
cursor: pointer;
}
.selectedclass{
background-color: #ff9;
}
</style>
<script type="text/javascript">
$(function(){
$('#customselector').customSelect();
});
</script>
</head>

<body>

<select name="select" class="customselect" title="" id="customselector">
<option value="icon1" title="images/attention.gif">Attention icon</option>
<option value="icon2" title="images/backward.gif">Back Icon</option>
<option value="icon3" title="images/base.gif">Base Icon</option>
</select>
</body>
</html> 


原文地址:http://www.corange.cn/archives/2012/04/3826.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
在HTML中,可以使用`<select>`和`<option>`标签来创建下拉选择框。然而,`<option>`标签并不能直接放置图片。它只能包含文本内容作为选项显示在下拉框中。 如果想要在下拉框中显示图片,可以使用其他的HTML和CSS技术。一种常见的方法是使用CSS的背景图像属性。首先,可以定义一个自定义的下拉框样式,并将其设置为一个有背景图像的元素。然后,可以通过JavaScript或者jQuery等技术来控制下拉框选项的显示与隐藏。 具体的实现步骤如下: 1. 在HTML中创建一个`<select>`元素,设置其ID,例如`<select id="mySelect">`。 2. 使用CSS样式来自定义下拉框样式,例如: ```css #mySelect { appearance: none; background: url('image.png') no-repeat; background-size: 20px 20px; padding: 10px; border: none; } #mySelect option { background-color: #FFF; color: #000; } ``` 3. 使用JavaScript(或jQuery)来控制下拉框选项的显示与隐藏,例如: ```javascript document.getElementById("mySelect").addEventListener("change", function() { var selectedOption = this.options[this.selectedIndex]; var imagePath = selectedOption.getAttribute('data-image'); document.getElementById("selectedImage").src = imagePath; }); ``` 4. 在HTML中创建一个用于显示选中图片的元素,例如: ```html <img id="selectedImage" src="default_image.png" alt="Selected Image"> ``` 5. 在每个`<option>`标签中添加`data-image`属性,并设置为对应选项的图片路径,例如: ```html <select id="mySelect"> <option data-image="image1.png">选项1</option> <option data-image="image2.png">选项2</option> <option data-image="image3.png">选项3</option> </select> ``` 通过以上的方法,就可以实现在下拉框中显示选项对应的图片了。具体表现效果可以根据个人需求进行样式的调整和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值