jquery - jquery-mobile 单选按钮中的数据图标

标签 jquery css jquery-mobile jquery-mobile-fieldset jquery-mobile-radio

我想用 data-icons in jquery mobile 中的一些图标替换我的单选按钮的文本.我的代码是这样的,on jsfiddle

<div data-role="page">
    <div data-role="content">
        <div data-role="fieldcontain">
            <fieldset data-role="controlgroup"><legend>Choose a direction:</legend>
                <input type="radio" name="1" id="1" value="1" />
                <label for="1">Up</label>
                <input type="radio" name="1" id="2" value="2" />
                <label for="2">Down</label>
            </fieldset>
        </div>
    </div>
</div>

我想用 data-icon="arrow-u"替换 'up',用 data-icon="arrow-d"替换 'down'。 This answer显示了如何替换为外部图像,但数据图标如何?

最佳答案

这是一个工作示例:http://jsfiddle.net/Gajotres/wL2gQ/

希望这就是您想要的。

HTML :

<div data-role="page" id="radio-icons"> 
    <div data-role="content"> 
        <div data-role="fieldcontain">
            <fieldset data-role="controlgroup">
                <input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked" />
                <label for="radio-choice-1" ><div id="custom-label"><span class="ui-icon ui-icon-bars ui-icon-shadow up">&nbsp;</span></div></label>

                <input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2"  />
                <label for="radio-choice-2"><div id="custom-label"><span class="ui-icon ui-icon-bars ui-icon-shadow down">&nbsp;</span></div></label>
            </fieldset>
        </div>
    </div>
</div>

CSS:

#custom-label {
    width: 18px;    
    height: 18px;
    background-color: rgba(0, 0, 0, 0.4);
    background-image: url("images/icons-18-white.png");
    background-repeat: no-repeat;
    border-radius: 9px 9px 9px 9px;  
}

#custom-label span {
    left: 45px !important;
    margin-top: -7px;
}

#custom-label span.up {
    background-position: -180px -1px !important;    
}

#custom-label span.down {
    background-position: -216px -1px !important;    
}

关于jquery - jquery-mobile 单选按钮中的数据图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15791062/

相关文章:

css - 将此自定义插入符放在正确的位置

javascript - 在 Bootstrap 模式上显示覆盖

html - 背景图像不透明度不起作用 [HTML/CSS]

jquery-mobile - 如何避免 jQuery 菜单在打开时滚动到顶部

jquery - 在ajax请求后重新初始化Jquery Mobile的所有元素?

performance - 寻找一种可靠的方法来测试移动设备上的 CSS 转换性能

javascript - 使用 jQuery 根据用户输入过滤列表

jquery - 单击外部 jQuery 选择器仍会激活功能

jquery - TypeError : $(. ..).owlCarousel 不是函数

javascript - jquery 兄弟属性