前端js中渲染html,点击事件传参为ID时,注意事项

前端js中渲染html案例: 

  let declareListHtml;
                for (let i = 0; i < declareInfo.length; i++) {
                    let declareId = declareInfo[i].id+""
                    declareListHtml += "<tr>"
                    declareListHtml += "<td>"+(i+1)+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].unit+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].name+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].sex+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].dateOfBirth+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].joinWorkTime+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].declareDegree+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].draduationDate+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].major+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].majorIn+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].jobTitle+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].workingYears+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].langueType+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].score+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].year+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].examForm+"</td>"
                    if (declareInfo[i].declarationForm == "declarationForm"){
                        declareListHtml +="<td> <button class='common_button' title='申报表' onclick='javaScript:declarationForm(\"" + declareId +"\")' >申报表</button></td>"
                    }
                    if (declareInfo[i].businessAutobiography == "businessAutobiography"){
                        declareListHtml +="<td> <button class='common_button' title='业务自传' onclick=''>业务自传</button></td>"
                    }
                    if (declareInfo[i].manuscript == "manuscript"){
                        declareListHtml +="<td> <button class='common_button' title='评议评价工作底稿' onclick=''>评议评价工作底稿</button></td>"
                    }
                    if (declareInfo[i].certificate == "certificate"){
                        declareListHtml +="<td> <button class='common_button' title='各类证件' onclick='javaScript:certificate(\"" + declareInfo[i].id +"\")'>各类证件</button></td>"
                    }
                    if (declareInfo[i].jobPerformance == "jobPerformance"){
                        declareListHtml +="<td> <button class='common_button' title='工作业绩' onclick='javaScript:jobPerformance(\""+declareInfo[i].id+"\")'>工作业绩</button></td>"
                    }
                    if (declareInfo[i].paper == "paper"){
                        declareListHtml +="<td> <button class='common_button' title='论文论著' onclick='javaScript:paper(\""+declareInfo[i].id+"\")'>论文论著</button></td>"
                    }
                    if (declareInfo[i].result == "result"){
                        declareListHtml +="<td> <button class='common_button' title='论文送审结果' onclick=''>论文送审结果</button></td>"
                    }
                    declareListHtml += "<td>"+declareInfo[i].formerYears+"</td>"
                    declareListHtml += "<td>"+declareInfo[i].remark+"</td>"
                    declareListHtml += "</tr>"
                }
                $('#dataSpan').html(declareListHtml)

1、 渲染过程中,要注意单引号与双引号的的使用

2、渲染过程中,在标签中直接渲染点击事件declarationForm并传参id,需要转义id,否则传递过程中会将id(id为长字符串)后三位自动转化为000

declareListHtml +="<td> <button class='common_button' title='申报表' onclick='javaScript:declarationForm(\"" + declareId +"\")' >申报表</button></td>"

οnclick='javaScript:declarationForm(\"" + declareId +"\")'

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值