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

猜你喜欢

转载自www.cnblogs.com/whosMeya/p/12321521.html