[BUG] Uncaught TypeError: Illegal invocation at HTMLDivElement.

现象

<div id="clickMe" key="1">点我</div>
clickMe.onclick = function (event) {
  var getAttribute = event.target.getAttribute;
  console.log(getAttribute('key'))
}
// TypeError: Illegal invocation at HTMLDivElement.clickMe.onclick

clickMe.addEventListener('click', function (event) {
  var getAttribute = event.target.getAttribute;
  console.log(getAttribute('key'))
})
// Uncaught TypeError: Illegal invocation at HTMLDivElement.

原因

getAttribute 方法不能赋值给变量.


原文地址:https://www.cnblogs.com/whosmeya/p/12321521.html