button的onclick事件給函數傳遞參數

ul+='<button onclick="pay(\''+regiId+'\')" >去支付</button>'   //此爲原生JS頁面拼接
    //regiId 爲變量

<button onclick="pay(\''+regiId+'\')" >去支付</button>
     //regiId 爲變量


 function pay(reg) {    //reg 爲變量,可隨意
        alert(reg)
    }

    //此方式的關鍵就在於轉義字符
相關文章
相關標籤/搜索