简体   繁体   English

如何在 jquery 中显示选中的复选框

[英]how to show checkbox as checked in jquery

enter image description here在此处输入图像描述

$(document).ready(function() {
        $('.editbtn').on('click', function(){

            $('#editmodal').modal('show');
            $tr=$(this).closest('tr');
            var data= $tr.children("td").map(function(){
              return $(this).text();
            }).get();
            console.log(data);

            $('#update_id').val(data[0]);
            $('#finame').val(data[1]);
            $('#liname').val(data[2]);
            $('#Eimail').val(data[3]);
            $('#ContactNumber').val(data[4]);
            $('#Giender').val(data[5]);
            $('#Dob').val(data[6]);
            $('#addriess').val(data[7]);
            $('#Ciity').val(data[8]);
            $('#pinicode').val(data[9]);
            $('#stiate').val(data[10]);
            $('#countiry').val(data[11]);
            $('#HobbyiDrawing').each(function(){ this.checked = true; });
            $('#HobbyiDrawing').each(function(){ this.checked = false; });
           // $('#HobbyiDrawing').attr('checked', true);
            $('#HighiSchool').val(data[13]);
        });
});

i want to checkbox and radio button as checked in update modal form how to resolve it please guide me我想在更新模式表单中检查复选框和单选按钮如何解决它请指导我

$('#HobbyiDrawing').attr("checked",true);

You can do it like this.你可以这样做。

try checked attribute in both input tags as give down尝试在两个输入标签中检查属性作为放弃

<input type="radio" name="color" value="red" checked>

<input type="checkbox" checked>

You can use this construction for check all checkbox via JQuery您可以使用此结构通过 JQuery 选中所有复选框

onclick="$('input[name*=\'selected\']').prop('checked', this.checked);"

For radio buttons you can use those methods - How to set radio button status with JavaScript对于单选按钮,您可以使用这些方法 - How to set radio button status with JavaScript

  • Set your dynamic value in values variable to checked checkbox or radio将值变量中的动态值设置为选中的复选框或单选框

 $('input[value='+values+'').attr('checked', true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM