简体   繁体   English

我可以在Yii下拉列表小部件中使用一些图片代替纯文本吗?

[英]Can I use some pictures instead of plain text in Yii dropdownlist widget?

<?php echo CHtml::dropDownList('listname', $select, array('M' => 'Male', 'F' => 'Female')); ?>

the example in the Yii site only shows how to set the options with plain text. Yii网站中的示例仅显示了如何使用纯文本设置选项。 Is there any way to set it with some pictures? 有什么办法设置一些图片吗?

Any help will be appreciated. 任何帮助将不胜感激。 Best regards! 最好的祝福!

Dropdownlist generates a select tag in client html, which doesn't support using image as its option. Dropdownlist在客户端html中生成一个选择标记,该标记不支持使用image作为其选项。

To use image as the option for a select, you can implement some code like the following: 要将图像用作选择的选项,可以实现如下代码:

<div style='position: relative'>
    <div class='usersel'>here to display what user select currently</div>
    <ul style='position: absolute'>
        <li><img src='1.png' /><span>text</span></li>
        <li><img src='2.png' /><span>text</span></li>
        <li><img src='3.png' /><span>text</span></li>
    </ul>
</div>

then use jQuery to catch event mousedown or mouseenter on the outer div, display the inner ul child, and bind click event to li, when li is clicked, set the div.usersel with the selected value. 然后使用jQuery捕获外部div上的mousedown或mouseenter事件,显示内部ul子级,并将click事件绑定到li,单击li时,将div.usersel设置为所选值。

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

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