qq_41572097 2019-12-03 17:36 采纳率: 25%
浏览 371

table 表里想让 第2列乘以第3列求和,再将数据打在第4列,然后让第四列做和,麻烦大神

麻烦大神帮帮忙,新手求帮助 正在学习js table 表里想让 第2列乘以第3列将数据打在第4列,然后让第四列做和,麻烦大神,
table表贴出来了

<table border="1px" style="width: 100%; height: 100%; border-spacing: 0rem; text-align: center;" >
                         <tr>
                           <th>评核项目</th>
                           <th>得分(0-100分)</th>
                           <th>权重</th>
                           <th>得分</th>
                         </tr>
                         <tr>
                           <td>仪表举止</td>
                           <td><input class="" style="width: 100%;height: 100%;border: 0px;"/></td>
                           <td><input class="" value="10%" readonly = "readonly"id="numb" style="width: 100%;height: 100%;border: 0px;"/> </td>
                           <td><input class=""  id="total" readonly = "readonly"  style="width: 100%;height: 100%;border: 0px;"/> </td>
                         </tr>
                         <tr>
                           <td>专业素质</td>
                           <td><input class="" style="width: 100%;height: 100%;border: 0px;"/></td>
                           <td><input class="" value="30%" readonly = "readonly"id="numb" style="width: 100%;height: 100%;border: 0px;"/> </td>
                           <td><input class=""  id="total" readonly = "readonly"  style="width: 100%;height: 100%;border: 0px;"/> </td>
                         </tr>
                         <tr>
                           <td>逻辑思维</td>
                           <td><input class="" style="width: 100%;height: 100%;border: 0px;"/></td>
                           <td><input class="" value="20%" readonly = "readonly"id="numb" style="width: 100%;height: 100%;border: 0px;"/> </td>
                           <td><input class=""  id="total" readonly = "readonly"  style="width: 100%;height: 100%;border: 0px;"/> </td>
                         </tr>
                         <tr>
                           <td>敬业精神</td>
                           <td><input class="" style="width: 100%;height: 100%;border: 0px;"/></td>
                           <td><input class="" value="10%" readonly = "readonly"id="numb" style="width: 100%;height: 100%;border: 0px;"/> </td>
                           <td><input class=""  id="total" readonly = "readonly"  style="width: 100%;height: 100%;border: 0px;"/> </td>
                         </tr>
                         <tr>
                           <td>沟通协调能力</td>
                           <td><input class="" style="width: 100%;height: 100%;border: 0px;"/></td>
                           <td><input class="" value="10%" readonly = "readonly"id="numb" style="width: 100%;height: 100%;border: 0px;"/> </td>
                           <td><input class=""  id="total" readonly = "readonly"  style="width: 100%;height: 100%;border: 0px;"/> </td>
                         </tr>
                         <tr>
                           <td>组织管理能力</td>
                           <td><input class="" style="width: 100%;height: 100%;border: 0px;"/></td>
                           <td><input class="" value="10%" readonly = "readonly"id="numb" style="width: 100%;height: 100%;border: 0px;"/> </td>
                           <td><input class=""  id="total" readonly = "readonly"  style="width: 100%;height: 100%;border: 0px;"/> </td>
                         </tr>
                         <tr>
                           <td>应变能力</td>
                           <td><input class="" style="width: 100%;height: 100%;border: 0px;"/></td>
                           <td><input class="" value="10%" readonly = "readonly"id="numb" style="width: 100%;height: 100%;border: 0px;"/> </td>
                           <td><input class=""  id="total" readonly = "readonly"  style="width: 100%;height: 100%;border: 0px;"/> </td>
                         </tr>
                         <tr>
                           <td>总计</td>
                           <td><input class="" value="—— ——" readonly = "readonly"style="width: 100%;height: 100%;border: 0px;"/></td>
                           <td><input class="" value="10%" readonly = "readonly"id="numb" style="width: 100%;height: 100%;border: 0px;"/> </td>
                           <td><input class=""  id="total" readonly = "readonly"  style="width: 100%;height: 100%;border: 0px;"/> </td>
                         </tr>
                       </table>

麻烦大神帮帮忙

  • 写回答

1条回答 默认 最新

  • Kuukiliselessness 2019-12-03 18:31
    关注

    下班了,先上代码,有什么其他问题明天再说...

    
    ((urTable)=>{
      let trs = urTable.querySelectorAll('tr');
      let total = urTable.querySelector('tr:last-child>td:last-child>input');
      for(let k = 1,len = trs.length - 1; k<len ;k++){
        let input_1 = trs[k].querySelector('td:nth-child(2)>input');
        if(!input_1){
          continue
        }
        let power = trs[k].querySelector('td:nth-child(3)>input'),
        grade = trs[k].querySelector('td:nth-child(4)>input');
        input_1.onchange = ()=>{
          grade.value = event.target.value * parseFloat(power.value.replace('%')) / 100
          trs[k].querySelector('td:nth-child(4)>input')
          total.value = 0
          total.value = Array.from(
            urTable.querySelectorAll('tr>td:nth-child(4)>input')
          ).reduce((all, {value} )=>{
            return all+parseFloat(value||0)
          }, 0);
        }
      }
    })(document.querySelector('table'));// 传入你的table
    
    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配