Bootstrap table checkbox默认样式修改

由于bootstrap表格默认的CheckBox样式比较丑,所以打算试着改一改

直接看效果图:

Bootstrap table checkbox默认样式修改_第1张图片

css样式

.bella-checkbox{
    position: relative;
}
/** 将初始的checkbox的样式改变 */
.bella-checkbox input[type="checkbox"] {
    opacity: 0; /*将初始的checkbox隐藏起来*/
}
/** 设计新的checkbox,位置 */
.bella-checkbox label:before {
    content: '';
    width: 19px;
    height: 19px;
    display: inline-block;
    border-radius: 2px;
    border: 1px solid #bbb;
    background: #fff;
}
/** 点击初始的checkbox,将新的checkbox关联起来 */
.bella-checkbox input[type="checkbox"]:checked + label:after {
    display: inline-block;
    font-family: 'Glyphicons Halflings';
    content: "\e013";
    top: 15%;
    left: 10%;
    position: absolute;
    font-size: 11px;
    line-height: 1;
    width: 16px;
    height: 16px;
    color: #333;
}
.bella-checkbox label {
    cursor: pointer;
    text-align: center;
    position: absolute;
    left: 10px;
}

js部分代码

onPostBody : function () {
	//$("input[type=checkbox]")
	//$("input[name='btSelectItem']")  btSelectAll
	 $("#tb_departments").find("input[name='btSelectItem']").each(function (i) {
	         var $check = $(this);
	         if ($check.attr("id") && $check.next("label")) {
	            return;
	         }
	         var name = $check.attr("name");
	         var id = name + "-" + i;
	         var $label = $('');
	         $check.attr("id", id).parent().addClass("bella-checkbox").append($label);
	})
	//全选CheckBox
	$("#tb_departments").find("input[name='btSelectAll']").each(function (i) {
	         var $check = $(this);
	         if ($check.attr("id") && $check.next("label")) {
	            return;
	         }
	         var name = $check.attr("name");
	         var id = name + "-" + i;
	         var $label = $('');
	         $check.attr("id", id).parent().addClass("bella-checkbox").append($label);
	})
}

 

你可能感兴趣的:(前端)