const googleDiv = function(){
const container = document.createElement('div');
const btnEle = document.createElement('button');
btnEle.type = "button";
btnEle.className = "link-btn";
btnEle.appendChild(document.createTextNode("(Unlink)"));
btnEle.onclick = "unlinkGoogle()";
container.appendChild(btnEle);
container.id = "google-linked-container";
return container;
};
이 방법으로 버튼을 만들면 버튼이 DOM에 아무런 문제가 없으며 버튼 유형 및 클래스가 예상대로 표시되지만 onclick 속성은 없습니다. 왜?onclick 속성이 등록되지 않았습니다.
P. btnEle.addEventListener("click",() => { console.log("clicked!"); });
도 작동하지 않습니다.
업데이트 내가 JSFiddle에 복제 한 : https://jsfiddle.net/fs1xhgnm/2/
JSFiddle @Ashley를 만들 수 있습니까? – Haring10
'addEventListener'로 잘 작동하는 것 같습니다. https://jsfiddle.net/fs1xhgnm/1/ – JJJ