Dir*_*Jan 1 css checkbox twitter-bootstrap
将输入复选框设为Bootstrap glyphicon是否可行?
我想用一个漂亮的Bootstrap glyphicon来组成默认复选框.例如:glyphicon glyphicon-unchecked当检查时:glyphicon glyphicon-check.
我试过这个:
input[type='checkbox'] {
position: relative;
top: 1px;
display: inline-block;
font-family: 'Glyphicons Halflings';
font-style: normal;
font-weight: 400;
line-height: 1;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
content: "\e157";
}
Run Code Online (Sandbox Code Playgroud)
但什么都没发生..
我不知道这是否可行?
您可以通过以下几种方法实现这一目标:
方法1
<label>标签内部,两个<tags>代表您需要放置的图标(或在外部,每个使用场景)<tags>在input[type='checkbox']选中或取消选中时切换这两个方法2
:before(或:after取决于你的情节)<label>content道具.在选中或取消选中:before时,您想要的图标input[type='checkbox']如果您能够稍微修改您的标记,则应该这样做:
<label for="myCheckbox" class="glyphy">
<input type="checkbox" id="myCheckbox" />
<span class="glyphicon glyphicon-unchecked"></span>
label words
</label>
$('.glyphy').click(function (e) {
if ($(e.target).is('input')) { // prevent double-event due to bubbling
$(this).find('.glyphicon').toggleClass('glyphicon-check glyphicon-unchecked');
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17161 次 |
| 最近记录: |