简体   繁体   English

使用带有多个参数的onclick函数从javascript添加按钮

[英]add button from javascript with an onclick function that takes multiple parameters

I am trying to add a button from a javascript function (with the innerHTML method) that has another function as the onClick function. 我试图从具有另一个功能作为onClick函数的javascript函数(使用innerHTML方法)添加按钮。 This onClick function has to take multiple parameters: 此onClick函数必须采用多个参数:

area.innerHTML += "<input type='image' src='images/del.jpg' width='15' height='15' " +
           "onClick='del(" + info['_id'] + "," + key + "," + value + ")' />";

This is (I think) the most logical way to do this, but when I try to click the button there is no functioncall. (我认为)这是最合理的方法,但是当我尝试单击按钮时,没有函数调用。 This works with one single argument, so the problem has to be in the combination of the parameters with the ",". 这仅适用于单个参数,因此问题必须在于参数与“,”的组合。 Does anybody know how to solve this? 有人知道如何解决这个问题吗?

update The del function is a temporary testfunction 更新 del函数是一个临时测试函数

function del(id, key, value) {
    console.log(id + key + value);
}

I think you just need your variabled to be passed as strings. 我认为您只需要将变量作为字符串传递即可。 Edit the onclick even to this: 甚至编辑onclick:

onClick='del(\"" + info['_id'] + "\",\"" + key + "\",\"" + value + "\")' />"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM