如何在复选框检查上设置粗体文本

时间:2016-11-15 06:27:28

标签: jquery

我按照下面的小提琴来设置复选框检查

上的粗体文字

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/

能告诉我如何使这项工作。

1 个答案:

答案 0 :(得分:1)

您可以通过纯jqueryjquery +&#39; css&#39 ;;

来实现这一目标

检查这个

&#13;
&#13;
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;
&#13;
&#13;