function showData(row) { var tr = document.createElement('tr'); var td1 = document.createElement('td'); td1.innerHTML = row.DEVID; var td2 = document.createElement('td'); td2.innerHTML = row.Area; var td3 = document.createElement('td'); td3.innerHTML = row.USERNAME; var td4 = document.createElement('td'); if (row.IsUsable == '1') { td4.innerHTML = "可用"; } else { td4.innerHTML = "不可用"; } var td5 = document.createElement('td'); td7.innerHTML = row.BindDate; tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); tr.appendChild(td4); tr.appendChild(td5);}我现在是写成这样的,但是页面显示 “可用不可用” 感觉不怎么好看,想用checkbox之类的的勾选来显示。那我这里应该怎么改呢?: var td4 = document.createElement('td'); if (row.IsUsable == '1') { td4.innerHTML = "可用"; } else { td4.innerHTML = "不可用"; }
登录后复制
回复讨论(解决方案)
function showData(row) { var tr = document.createElement('tr'); var td1 = document.createElement('td'); td1.innerHTML = row.UID; var td2 = document.createElement('td'); td2.innerHTML = row.AREA; var td3 = document.createElement('td'); td3.innerHTML = row.USERNAME; var td4 = document.createElement('td'); if (row.ROLE == '1') { td4.innerHTML = "是"; } else { td4.innerHTML = "否"; } var td5 = document.createElement('checkbox'); if (row.ISUSSELF == '1') { document.getElementById("checkbox").checked = true } else { document.getElementById("checkbox").checked = false } var td6 = document.createElement('td'); td6.innerHTML = row.ISUSABLE; tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); tr.appendChild(td4); tr.appendChild(td5); tr.appendChild(td6);; $("#datatable > tbody").append(tr); }
登录后复制
我现在这样完全不行啊,求赐教!
首先下面的代码就不正确,根本取不到你要的元素:
document.getElementById("checkbox").checked = true
登录后复制
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">无标题文档 var row = {}; row.UID = "1"; row.AREA = "China"; row.USERNAME = "Li Ming"; row.ROLE = '1'; row.ISUSSELF = '1'; $(function () { showData(row); }); function showData(row) { var tr = document.createElement('tr'); var td1 = document.createElement('td'); td1.innerHTML = row.UID; var td2 = document.createElement('td'); td2.innerHTML = row.AREA; var td3 = document.createElement('td'); td3.innerHTML = row.USERNAME; var td4 = document.createElement('td'); if (row.ROLE == '1') { td4.innerHTML = "是"; } else { td4.innerHTML = "否"; } var chkbox = document.createElement('input'); chkbox.setAttribute("type", "checkbox"); if (row.ISUSSELF == '1') { chkbox.setAttribute("checked", true); } else { chkbox.setAttribute("checked", false); } var td6 = document.createElement('td'); td6.innerHTML = row.ISUSABLE; tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); tr.appendChild(td4); tr.appendChild(chkbox); tr.appendChild(td6);; $("#datatable > tbody").append(tr); }
登录后复制登录后复制
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">无标题文档 var row = {}; row.UID = "1"; row.AREA = "China"; row.USERNAME = "Li Ming"; row.ROLE = '1'; row.ISUSSELF = '1'; $(function () { showData(row); }); function showData(row) { var tr = document.createElement('tr'); var td1 = document.createElement('td'); td1.innerHTML = row.UID; var td2 = document.createElement('td'); td2.innerHTML = row.AREA; var td3 = document.createElement('td'); td3.innerHTML = row.USERNAME; var td4 = document.createElement('td'); if (row.ROLE == '1') { td4.innerHTML = "是"; } else { td4.innerHTML = "否"; } var chkbox = document.createElement('input'); chkbox.setAttribute("type", "checkbox"); if (row.ISUSSELF == '1') { chkbox.setAttribute("checked", true); } else { chkbox.setAttribute("checked", false); } var td6 = document.createElement('td'); td6.innerHTML = row.ISUSABLE; tr.appendChild(td1); tr.appendChild(td2); tr.appendChild(td3); tr.appendChild(td4); tr.appendChild(chkbox); tr.appendChild(td6);; $("#datatable > tbody").append(tr); }
登录后复制登录后复制
var td5= document.createElement(‘input’);
td5.setAttribute(“type”, “checkbox”);
if (row.ISUSSELF == ‘1’) {
td5.setAttribute(“checked”, true);
}
else {
td5.setAttribute(“checked”, false);
}
这样写表格就乱了,能把document.createElement(‘input’);加入到document.createElement(‘td’);里吗?
你都引入jquery了为什么不用jquery呢?,你是取会数据拼装table的tr,td吗?
你都引入jquery了为什么不用jquery呢?,你是取会数据拼装table的tr,td吗?
是啊,但是不是很会用
function showData(row) {var str='';str+=''+row.UID+''+row.AREA+''+ row.USERNAME+'';str+=(row.ROLE == '1')?'是':'否';str+=''+row.ISUSABLE;+''; $("#datatable > tbody").append($(str)); }
登录后复制
nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">无标题文档
登录后复制登录后复制 jQuery(function($){var row = {}; row.UID = “1”; row.AREA = “China”; row.USERNAME = “Li Ming”; row.ROLE = ‘1’; row.ISUSSELF = ‘1’;//showData(row); //function showData(row) { var str=”; str+=’
‘+row.UID+’ ‘+row.AREA+’ ‘+ row.USERNAME+’ ‘; str+=(row.ROLE == ‘1’)?’是’:’否’; str+=’ ‘+row.ISUSSELF+”; $(“#datatable > tbody”).append($(str)); //}});nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">无标题文档
登录后复制登录后复制 jQuery(function($){var row = {}; row.UID = “1”; row.AREA = “China”; row.USERNAME = “Li Ming”; row.ROLE = ‘1’; row.ISUSSELF = ‘1’;//showData(row); //function showData(row) { var str=”; str+=’
‘+row.UID+’ ‘+row.AREA+’ ‘+ row.USERNAME+’ ‘; str+=(row.ROLE == ‘1’)?’是’:’否’; str+=’ ‘+row.ISUSSELF+”; $(“#datatable > tbody”).append($(str)); //}});谢谢了 ,挺好的方法,修改下就可以了
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/2842043.html