Javascript 无法将参数传递给按钮标记内的onclick函数

Javascript 无法将参数传递给按钮标记内的onclick函数,javascript,html,onclick,Javascript,Html,Onclick,我的代码中有以下行: items.push("</font><button onclick='addToItinerary();' class='coolbutton' style='float: right;' id='" + results[i] + "'>add</button></ol><br> </br>"); 项。推送(“添加”; 我想将一个参数传递到addToIntererary函数(results[I])

我的代码中有以下行:

items.push("</font><button onclick='addToItinerary();' class='coolbutton' style='float: right;' id='" + results[i] + "'>add</button></ol><br> </br>");
项。推送(“添加

”;

我想将一个参数传递到addToIntererary函数(results[I]),但尽管阅读了一些对类似问题的回答,我仍然无法理解它!发生什么事?提前谢谢。

将此作为参数传递。然后,函数将接收button元素作为参数。要获得
结果[i]
它可以访问参数的
.id
属性

items.push("</font><button onclick='addToItinerary(this);' class='coolbutton' style='float: right;' id='" + results[i] + "'>add</button></ol><br> </br>");
项。推送(“添加

”;
我有函数addToInternerary(按钮){},如何访问id?我尝试了button.getAttribute('id'),但在控制台中登录时收到的是[object],而不是名称。有什么关于我如何去做的建议吗?我想这应该行得通,但我只想写
button.id
。我不知道你为什么会从这里得到一个对象,我怀疑你做了别的错事。
results[I]
的值是多少?你确定那是一根绳子吗?你是对的,那不是一根绳子!对不起,是我的错。但是谢谢你的帮助!我已经弄明白了:)