繁体   English   中英

当数据来自数据库时,如何检查html表中的CheckBox? 在asp.net MVC中

[英]How to Check CheckBox in html table when data is coming from Database? in asp.net MVC

我正在通过ajax从页面加载的数据库中获取数据,我想在OptFlag为M时检查CheckBox。

$("#tblDelChkList tbody").append('<tr id="DelChkListRow1' + (rowCount++) + '" data-tr-count="' + (dataCount++) + '">' +
         '<td>' + SNo++ + '</td>' +
         '<td> <label id="lblDelChkListCode">' + item.DelChkListCode.trim() + ' </label></td>' +
         '<td> <label id="lblDelChkListDesc">' + item.DelChkListDesc.trim() + ' </label>' +
         '<input type="text" style="display:none;" class="form-control" id="txtDocTypeDesctbl"></td>' +
         'if('+item.OptFlag+' == "M"){'+
         '<td style="text-align:center;">' +         
         '<input type="checkbox" id="chkOptFlag" class="chkBank icheckbox_minimal-blue" checked="true" >'+
         '<input type="hidden" id="hdnDocCode" value="' + item.DelChkListCode.trim() + '"/>' +
         '</td>'+
          '}else{'+
          '<td style="text-align:center;">' +         
          '<input type="checkbox" id="chkOptFlag" class="chkBank icheckbox_minimal-blue" >'+
          '<input type="hidden" id="hdnDocCode" value="' + item.DelChkListCode.trim() + '"/>' +
          '</td>}' +
          '</tr>');
      });

这就是我得到的

在此处输入图片说明

你需要做类似的事情

jQuery以index.js结尾

let users=[
    {name:'John',isMarried:true},
    {name:'Uzair',isMarried:false},
    {name:'John',isMarried:true},
        {name:'Ab',isMarried:false}
]

$(function(){

    let str='';
    users.forEach(element => {
        str+="<tr>";
        str+="<td>";
        str+=element.name;
        str+="</td>"
        str+="<td>";
        if(element.isMarried){
            str+="<input type='checkbox' id='chkOptFlag' class='chkBank icheckbox_minimal-blue' checked='true'>";
        }else{
            str+="<input type='checkbox' id='chkOptFlag' class='chkBank icheckbox_minimal-blue'>";
        }
        str+="</td>";
        str+="</tr>";
    });

    $("#tblDelChkList").append(str)
})

HTML结尾

<body>
    <table>
        <thead>
            <tr>
                <td>Name</td>
                <td>Is Married?</td>
            </tr>
        </thead>
        <tbody id="tblDelChkList">

        </tbody>
    </table>

</body>
<script src="index.js"></script>

结果

查看详情

暂无
暂无

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

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