我正在使用JavaScript填充<div>
标记与其他<div>
s。它一直在工作,直到我更改了onclick事件中使用的标识符。旧名称(指数)从0-1000只是一个小数目,但新标识(ID)是uuid.v4()生成的字符串,它看起来像这样:失踪)参数后,但只为一个长字符串
f5ec8170-e75c-4a93-9997-1a683b7d2e00
我有相同的代码索引和id。但每当我点击它是假设激活函数调用的ID作为自变量,它给我的按钮:争吵后
失踪)
这不,当我点击发生按钮与索引做同样的事情,而不是id。
我的代码:
var id = messages[i].id;
var index = 0;
var newElement =
'<div class="fullMessage" id="fullRightMessage' + i + '">'+
'<h6 class="textMessage">' + messages[i].comment + '</h6>' +
'<button class="likeButtonMessage" onclick="likeClicked(right, ' + index + ', 1);">LIKE</button>' +
'<button class="dislikeButtonMessage" onclick="likeClicked(right, ' + id + ', -1);">DIS</button>' +
'<h4 id="scoreright' + i + '" class="messageScore">' + messages[i].score + '</h4>' +
'</div>'
您需要通过'串''''''''''''''按钮''''按钮onclick =“likeClicked(right,\''+ index +'\',1);”> LIKE'', – Satpal
@Satpal typo?编号,而不是索引,这将产生不良的HTML - 你需要转义撇号,而不是加双引号 –