var template='<div class="m-modal">\
<div class="modal_align"></div>\
<div class="modal_wrap">\
<div class="bk"></div>\
<div class="modal_body">\
<h3>登錄網(wǎng)易云課堂</h3>\
<div class="form1">\
<input value="賬號">\
</div>\
<div class="form2">\
<input value="密碼">\
</div>\
<button class="submit">登錄</button>\
</div>\
</div>\
</div>'
var container;
function html2node(str){
container = document.createElement('div');
container.innerHTML = str; return container.children[0];
}
var _layout=html2node(template);
var show=function(){
var asd=document.getElementById("parent");
asd.appendChild(_layout);
}
container.querySelector('.bk').addEventListener('click', function(event){
_layout.parentNode.removeChild(_layout);
});在chrome中的調(diào)試面板中,為何container只有一個div元素,根據(jù)container.innerHTML = str;這句,應(yīng)該顯示template元素啊?
還是js的問題啊
ITMISS
2018-08-21 14:13:19