原生js节点元素替换

HTML部分

<table>
 <tr>
   <td class="d">
     1231
   td>
   <td class="a">
     <input type="text" value="1">
   td>
   <td class="b">
     <input type="text" value="2">
     <img src="" alt="">
   td>
   <td class="c">
     <table>
       <tr>
         <td>
           <input type="text" value="3">
         td>
       tr>
     table>
   td>
 tr>
 <tr>
   <td>
     <input type="checkbox" name="data" value=""><input type="checkbox" name="data" value="">td>
   <td>
     <input type="checkbox" name="time" value="22"><label for="">22label>
     <input type="checkbox" name="time" value="33"> 33
   td>
   <td>
     <table>
       <tr>
         <td>
           <textarea name="" class="sss">textarea>
         td>
       tr>
     table>
   td>
   <td>
     <label for="remmber" class="input-checkbox">
       <input class="remmber" type="checkbox" name="remmber" id="remmber">
       <span>span>
       记住密码
     label>
     <label for="radio" class="input-radio">
       <input class="remmber" type="radio" name="rr" id="radio">
       <span>span>
       单选框
     label>
     <label for="radio2" class="input-radio">
       <input class="remmber" type="radio" name="rr" id="radio2">
       <span>span>
       单选框
     label>
   td>
   <td>td>
 tr>
table>
<button>123button>

CSS部分

table input[type="text"] {
    border: none;
    background: none!important;
    border-bottom: 1px solid #E0E3E4!important;
    border-radius: 0;
}
table textarea {
     border: none;
     border-bottom: 1px solid #E0E3E4;
     background: none;
 }
table textarea.BigStatic1 {
    background: none;
    border: none;
    border-bottom: 1px solid #e0e3e4;
}
table input.SmallButtonA {
    background: #4D7AE5;
    color: #fff;
    border-radius: 0;
    border: none;
    margin-bottom: 10px;
    height: 25px;
    line-height: 25px;
}
table button.DATA{
    background: url("oaimg/dataBtnImg.png") no-repeat;
    height: 20px;
    width: 23px;
    border:none;
    color: rgba(0,0,0,0);
    overflow: hidden;
}
table button:focus{
    outline: none;
}
table div[id^='LISTVIEW_DATA'] > span {
    display: none;
}
table input.LIST_CAL {
    display: none;
}
table .LIST_VIEW td,table  .LIST_VIEW th {
    border: 1px solid #aaa;
    background: rgba(0,0,0,0)!important;
}
table tr.LIST_VIEW_HEADER {
    height: 30px;
    background: #F2F3F6;
    color: #666;
}
table select {
    border: none;
    appearance:none;
    -moz-appearance:none;
    -webkit-appearance:none;
    background: url("oaimg/arrow.png") no-repeat scroll right center transparent;
    padding-right: 14px;
    border-bottom: 1px solid #E0E3E4;
    border-radius: 0;
}
table select::-ms-expand { display: none; }
table .remmber {
    display: none;
}
table .remmber[type=checkbox]+span {
    display: inline-block;
    border-radius: 0;
    width: 15px;
    height: 15px;
    /*border: 1px solid #2ac845;*//*复选框边框*/
    color: #fff;/*复选框钩的颜色*/
    position: absolute;
    top: 3px;
    left: -20px;
    background: #2ac845;/*复选框背景颜色*/
}
table .remmber[type=checkbox]:checked+span:after {
    content: '\2714';
    position: absolute;
    font-size: 14px;
    left: 2px;
    top:-3px;
}
table .remmber[type=radio]+span {
    display: inline-block;
    border-radius: 100px;
    width: 16px;
    height: 16px;
    /*border: 1px solid #2ac845;*//*单选框边框*/
    position: absolute;
    top: 3px;
    left: -20px;
    background: #2ac845;/*单选框背景颜色*/
}
table .remmber[type=radio]:checked+span:after {
    content: '';
    position: absolute;
    font-size: 14px;
    left: 50%;
    top:50%;
    margin-left: -4px;
    margin-top: -4px;
    width: 8px;
    height: 8px;
    border-radius: 100px;
    background: #fff;/*单选框中间圆圈背景颜色*/
    border: none;
}
table .input-checkbox,table .input-radio{
    position: relative;
    margin-left: 20px;
}
table input.ConcelBigInput,table textarea.ConcelBigInput{
    background: none!important;
    border-bottom: 1px solid #eee!important;
}
table input[readonly]{
    border:none;
    cursor: not-allowed;
}
.LIST_VIEW td input[type="button"]:first-child{
    background: url("oaimg/addListImg.png") no-repeat!important;
    height: 20px!important;
    width: 23px!important;
    border:none!important;
    color: rgba(0,0,0,0)!important;
    overflow: hidden!important;
}
.LIST_VIEW td input[value="删除"]:last-child{
    background: url("oaimg/deleteListImg.png") no-repeat!important;
    height: 20px!important;
    width: 23px!important;
    border:none!important;
    color: rgba(0,0,0,0)!important;
    overflow: hidden!important;
}

js部分

let inputArray = document.getElementsByTagName('input');
Array.prototype.slice.call(inputArray).map(ele => {
  if(!ele.classList.contains('remmber') && ele.getAttribute('type') == 'checkbox') {
    let name = ele.getAttribute('name'), value = ele.getAttribute('value'), text = '';
    let parent = ele.parentElement;
    if(ele.nextSibling.nodeType == '3') { // 判断当前节点的下一个节点是否为文本
      text = ele.nextSibling.nodeValue;
      parent.removeChild(ele.nextSibling); // 删除
    }
    let newNode = document.createElement('label'); // 创建新元素
    newNode.classList.add("input-checkbox");
    newNode.innerHTML = '+ name + ' value="' + value + '"">' + text;
    parent.replaceChild(newNode, ele); // 新旧元素替换
  }
});

你可能感兴趣的:(2020/02/28,随笔)