使用JavaScript,我创建了一个按钮,其中包含一个单击时触发的功能。正在将三个参数传递给函数id
,clientid
和title
。一切都是字符串。使用可以通过单击Demo1按钮演示的第一种方法,我收到错误
"Expected ')'"
使用可以通过单击Demo2按钮演示的第二种方法,我可以成功触发该函数,但是日志读取时好像是期望5个参数而不是3个。
//console.log(id, clientid, title);
10636,8154,New Opportunity - 1926 Grand Avenue, LLC 5/22/2018 undefined undefined
//console.log(title)
undefined
如何正确传递title
?
(function() {
var id = "10636";
var clientid = "8154";
var title = "New Opportunity - 1926 Grand Avenue, LLC 5/22/2018";
console.log('<button style="background-color: #00539B; border: 1px solid #00539B; color: white; border-radius: 4px;" onclick="openAddModal(\'' + id + ',' + clientid + ',' + title + '\')" />' + id + "</button>");
document.getElementById("demo1").innerHTML = "<button style='background-color: #00539B; border: 1px solid #00539B; color: white; border-radius: 4px;' onclick=openAddModal(" + id + ',' + clientid + ',' + title + ")>" + 'Demo1' + "</button>"
document.getElementById("demo2").innerHTML = '<button style="background-color: #00539B; border: 1px solid #00539B; color: white; border-radius: 4px;" onclick="openAddModal(\'' + id + "," + clientid + "," + title + '\')" />' + 'Demo2' + "</button>"
})();
function openAddModal(id, clientid, title) {
console.log(id, clientid, title);
console.log(title);
}
<span id="demo1"></span>
<span id="demo2"></span>