我按照下面的小提琴来设置复选框检查
上的粗体文字http://jsfiddle.net/CjpmP/2420/
我已尝试过如上所述,但这不起作用且控制台下也没有错误
这是我的代码
var myarray = ["A", "B", "C", "D", "E", "F", "G", "H"];
var counter = 0;
$(document).ready(function()
{
var html = ''
for (var i = 0; i < myarray.length; i++)
{
html += '<td><label class="mt-checkbox mt-checkbox-outline label-for-check"><input type="checkbox" class="chkclass check-with-label">' + myarray[i] + '<span></span></label></td>';
if ((i + 1) % 4 == 0) html += '</tr><tr>';
}
$("#tagstable tbody").append('<tr>' + html + '</tr>');
});
这是我的小提琴
https://jsfiddle.net/dHZS9/734/
能告诉我如何使这项工作。
答案 0 :(得分:1)
您可以通过纯jquery
或jquery
+&#39; css&#39 ;;
检查这个
var myarray = ["A", "B", "C", "D", "E", "F", "G", "H"];
var counter = 0;
$(document).ready(function()
{
var html = ''
for (var i = 0; i < myarray.length; i++)
{
html += '<td><label class="mt-checkbox mt-checkbox-outline label-for-check"><input type="checkbox" class="chkclass check-with-label">' + myarray[i] + '<span></span></label></td>';
if ((i + 1) % 4 == 0) html += '</tr><tr>';
}
$("#tagstable tbody").append('<tr>' + html + '</tr>');
});
//jquery with css
$(document).on("change", ".chkclass.check-with-label", function(){
$(this).closest("label").toggleClass("bold");
});
/*pure jquery
$(document).on("change", ".chkclass.check-with-label", function(){
var label = $(this).closest("label");
if($(this).is(":checked")){
$(label).css("font-weight",700);
}else{
$(label).css("font-weight",400);
}
});*/
&#13;
.bold{
font-weight: 700;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<table class="table" id="tagstable">
<tbody>
</tbody>
</table>
<button type="button" class="btn btn-success addTagbtn">Add new tag</button>
&#13;