簡體   English   中英

在javascript中的setAttribute“onclick”函數參數中傳遞參數

[英]pass a parameter in setAttribute "onclick" function argument in javascript

第 163 行

在第 163 行,我想為 close item 設置一個函數。 關閉是這里的一個按鈕。 我想通過它的“onclick”事件傳遞一個參數。 那就是它的id。 我該怎么做?

在這種情況下,您最好使用事件偵聽器,而不是嘗試使用 setAttribute 操作 onclick:

close.addEventListener("click", function(){
    //do what you need here: call another function, do some math, etc...
    checker('id'); //???
});

您可以使用:

close.onclick = function(){
    checker('id'); // <-- are you sure you want to pass static string here?
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM