重要: JS onclick() 函数中, 取不到 this !!!
错误的写法:
- function test(){
- $(this).parent().addClass('active')
- }
正确的写法是: 函数定义时带参数, 调用时传入 this
- function test(param){
- $(param).parent().addClass('active')
- }
- <button onclick="test(this)">
来源: http://www.bubuko.com/infodetail-2877777.html