我有以下代码,我想在父div中添加
{{1}}
答案 0 :(得分:1)
添加<div>
这里已经回答了 Add/remove HTML inside div using JavaScript
var jsonArr = [{
'id': 1,
'name': 'RAJ'
}, {
'id': 2,
'name': 'RAY'
}, {
'id': 3,
'name': 'RAM'
}];
function addDiv() {
for (var i = 0; i < jsonArr.length; i++) {
var div = document.createElement('div');
div.innerHTML = '<div style="width: 100%; overflow: hidden;">' +
'<div style="width: 10%; float: left;">' +
'<div><img src="assets/img/abc.png" style="height: 35;margin-left: 10; margin-right: 5px;"/></div> <div id="toro" style="color: black">' + jsonArr[i].id + '</div>' +
'</div>' +
'<div style="margin-left: 25%;">' +
'<div style="margin-top: 7;font-weight: bold; color: black"> <b>hie</b></div> <div style="color: black" >' + jsonArr[i].name + '</div><div style="float: right" id="time">'+new Date()+'</div></div>';
document.getElementById('parent').appendChild(div);
}
}
&#13;
<div id="parent">Parent div
</div>
<button onClick="addDiv()">Add Div</button>
&#13;