const $ = require('jquery'); // require('./../resource/layui/layui.all.js') // require('./../resource/layui/css/layui.css') // const layui = require('layui-src'); // console.log('layui', layui) // layui.use('table', function(){ // var table = layui.table; // //第一个实例 // table.render({ // elem: '#demo' // ,height: 312 // ,url: '/demo/table/user/' //数据接口 // ,page: true //开启分页 // ,cols: [[ //表头 // {field: 'id', title: 'ID', width:80, sort: true, fixed: 'left'} // ,{field: 'username', title: '用户名', width:80} // ,{field: 'sex', title: '性别', width:80, sort: true} // ,{field: 'city', title: '城市', width:80} // ,{field: 'sign', title: '签名', width: 177} // ,{field: 'experience', title: '积分', width: 80, sort: true} // ,{field: 'score', title: '评分', width: 80, sort: true} // ,{field: 'classify', title: '职业', width: 80} // ,{field: 'wealth', title: '财富', width: 135, sort: true} // ]] // }); // }); const data = [ { name: '入院记录', score: 10 }, { name: '入院记录', score: 10 }, { name: '入院记录', score: 10 },{ name: '入院记录', score: 10 } ,{ name: '入院记录', score: 10 } ,{ name: '入院记录', score: 10 }, { name: '入院记录', score: 10 } ] function renderTab(){ let str = ``, sum = 0 for(let i = 0; i < data.length; i++){ str += ` ${data[i].name} ` if(data[i].score){ sum += Number(data[i].score) } } str += ` 总分 ${sum} ` $('table tbody').html(str) bindInput() } renderTab() function bindInput(){ $('input').on('input', function(e){ const val = $(this).val() const index = $(this).attr('data-index') data[index].score = val renderTab() }) }