case 'copy': var B1 = document.getElementById("B1"); //获得B1下的html文本 var copy_dom = document.getElementById("copy_dom"); //获得B1下的html文本 var str = B1.parentNode.innerHTML; var btnstr = '<button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="confirm" id="id_confirm">确定</button>'; //<select name="provid" id="B1" lay-filter="provid_B2"> str = str.replace(/<select name="provid" id="B1" lay-filter="provid_B2">/g, '<select>'); if (document.getElementById("id_confirm") == null) { var tmp = document.createElement('button'); tmp.classList = "layui-btn layui-btn-sm layui-btn-normal"; var atr = document.createAttribute("lay-event"); //创建一个属性节点 atr.nodeValue = "confirm"; //设置属性节点值 tmp.setAttributeNode(atr); atr = document.createAttribute("id"); //创建一个属性节点 atr.nodeValue = "id_confirm"; //设置属性节点值 tmp.setAttributeNode(atr); var node = document.createTextNode("确定"); tmp.appendChild(node); copy_dom.parentNode.appendChild(tmp); } copy_dom.innerHTML = str; form.render(); break; case 'confirm': layer.msg("完成!"); var copy_dom = document.getElementById("copy_dom"); //获得B1下的html文本 copy_dom.innerHTML = ""; var t = this; this.parentNode.removeChild(this); //移除该节点 break;
//移除节点 var copy_dom = document.getElementById("copy_dom"); copy_dom && (copy_dom.innerHTML = ""); var id_confirm = document.getElementById("id_confirm"); id_confirm && (id_confirm.parentNode.removeChild(id_confirm));