重要:js onclick() 函数中,取不到this !!!

错误的写法:

function test(){
$(this).parent().addClass('active')
}

正确的写法是:函数定义时带参数,调用时传入this

function test(param){
$(param).parent().addClass('active')
}

<button onclick="test(this)">

 

相关文章:

  • 2021-11-29
  • 2022-12-23
  • 2021-11-13
  • 2021-08-01
  • 2022-12-23
  • 2021-12-22
猜你喜欢
  • 2022-02-19
  • 2022-03-02
  • 2021-10-21
  • 2021-05-29
  • 2021-06-01
  • 2022-12-23
  • 2022-02-01
相关资源
相似解决方案