将多个参数传递给函数missing)

时间:2019-06-20 12:20:18

标签: javascript arguments parameter-passing

我正在尝试创建一个取消操作并将页面恢复到其旧状态的函数,但在参数列表后出现错误Uncaught SyntaxError:missing


Peter R de Vries  oldname
NodeList(2) [p, p] infoarray
Pakket       oldpackage
€1300   oldpayment

NodeList(4) [li, li, li, li] oldeservicesarray




 let oldName = document.querySelector("#nameText").textContent;
    let infoArray = document.querySelectorAll(".customerInfo p");
    let oldPackage = document.querySelector(".customerPackage").textContent;
    let oldPayment = document.querySelector(".customerPayment").textContent;
    let oldServicesArray = document.querySelectorAll(".customerServices ul li");

 `<button type="button" class="btn btn-danger" onclick="cancel(${oldName},${infoArray},${oldPackage},${oldPayment},${oldServicesArray})">Cancel</button>`

function cancel(name,info,package,payment,services){
    console.log(name,info,package,payment,services);
}

通过全局设置参数并使用单独的函数来解决,以将eventlistener添加到新创建的按钮中,然后将其传递给cancel函数

function cancelEvent(){
    document.querySelector(".cancel").addEventListener("click",cancel(oldName,infoArray,oldPackage,oldPayment,oldServicesArray));
}

参数列表后未捕获到的SyntaxError:缺少

0 个答案:

没有答案