如何在HTML javascript中创建带有图标的选择框?

时间:2013-08-04 06:58:18

标签: javascript jquery html impromptu

我想创建一个对话框,从图标网格中选择一个特定的图标。就像这样: enter image description here

我正在使用jQuery Impromptu对话框用于我的其他对话框使用。但我不知道如何制作这个东西。请帮助我是新手。

1 个答案:

答案 0 :(得分:1)

我猜你可以把一堆链接放在一个容器里,然后在里面放一个img。

<div class="iconSelector">
    <a href="selecticon.php?icon=1" title="Select 'computer icon'"
       ><img src="computer.png" alt="computer icon"/></a>
    <a href="selecticon.php?icon=2" title="Select 'other icon'"
       ><img src="computer.png" alt="other icon"/></a>
    <a href="selecticon.php?icon=3" title="Select 'computer icon'"
       ><img src="computer.png" alt="computer icon"/></a>
  ...
</div>

然后,只需要一点点CSS就可以了:

.iconSelector {
    display: inline-block;
    padding: 8px;
}
.iconSelector a img {
    width: 32px; 
    height: 32px;
}

Demo fiddle

如果您愿意/需要,您也可以添加一些Javascript来处理点击。

$(function(){
    $('.iconSelector').on('click', 'a', function(e){
        e.preventDefault();
        alert($(this).attr('href') + ' was clicked');
    });
});

Demo fiddle