onclic事件传值发生变化的问题
项目上偶然遇见a标签的点击事件,传值有误的情况:
1、问题描述:通过js代码拼接了一段html代码,通过断点看,拼接的html里参数都正常,就是通过点击事件,参数到点击方法时,值发生变化,代码如下:
landHtml:function(e){ var landInfo = e.land; var h = ""; h += "<div class='open-info-text-row'><div class='open-info-text-key'>宗地号:</div><div>" + landInfo.landParcelCode + "</div></div>"; h += "<div class='open-info-text-row'><div class='open-info-text-key'>权利人:</div><div>" + landInfo.obligeeName + "</div></div>"; h +="<div class='ivu-table ivu-table-border'>"; h +="<div class='ivu-table-header' style='font-weight: bolder;'>"; h +='<table cellspacing="0" cellpadding="0" border="0" style="width:100%;">'; h +="<tr><td style='width:30%'>权利人关系</td><td>企业名称</td>"; h +="</table>"; h +="</div>"; h +="<div class='ivu-table-body'>"; h +='<table cellspacing="0" cellpadding="0" border="0" style="width:100%;">'; if (e.entList && e.entList.length > 0){ for (var i = 0; i < e.entList.length; i++) { var owership = "权利单位"; if (e.entList[i].ownershipType == 1){ owership = "承租企业"; } h += "<tr><td style='width:30%'>"+ owership +"</td><td><a onclick=openEntInfo('"+ e.entList[i].spCode +"')>"+ e.entList[i].spName +"</a></td></tr>" } } h +="</table>"; h +="</div></div>"; return h; }
2、将上一段运行完的html代码复制出来,如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>ceshi</title> <meta charset="UTF-8" /> </head> <style> a { color:#39f; cursor: pointer; } a:hover{ text-decoration:underline; } </style> <body> <div class='open-info-text-row'><div class='open-info-text-key'>宗地号:</div><div>25008</div></div> <div class='open-info-text-row'><div class='open-info-text-key'>权利人:</div><div>xx有限公司</div></div> <div class='ivu-table ivu-table-border'> <div class='ivu-table-header' style='font-weight: bolder;'> <table cellspacing="0" cellpadding="0" border="0" style="width:100%;"><tr><td style='width:30%'>权利人关系</td><td>企业名称</td></table> </div> <div class='ivu-table-body'> <table cellspacing="0" cellpadding="0" border="0" style="width:100%;"> <tr> <td style='width:30%'>权利单位</td> <td><a onclick=openEntInfo(2854257231529985)>a有限公司</a></td> </tr> <tr> <td style='width:30%'>承租企业</td> <td><a onclick=openEntInfo(11699043894728605938)>b有限公司</a></td> </tr> <tr> <td style='width:30%'>承租企业</td> <td><a onclick=openEntInfo(11699043894728605937)>c有限公司</a> </td> </tr> <tr> <td style='width:30%'>承租企业</td> <td><a onclick=openEntInfo(11699043894728605936)>d科技有限公司</a> </td> </tr> </table> </div> </div> <script type="text/javascript"> function openEntInfo (spCode){ alert(spCode); } </script> </body> </html>
3、点击b有限公司的时候,发现参数值不是 11699043894728605938,非常疑惑!
解决:参数加引号就ok
<td><a onclick=openEntInfo('11699043894728605938')>b有限公司</a></td>