[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 方法不能赋值给变量.


posted @ 2020-02-17 14:03  whosmeya  阅读(521)  评论(0编辑  收藏  举报