例子代码: http://codepen.io/hj624608494... 问题出现在 this的指向 this永远指向函数执行时的对象. function choose(){ alert($(this).data('name')); // undefind 因为choose函数的this指向的是window } function choose2(){ $('#J_a').click(function(){ // 这个点击事件的匿名函数的this 指向的是 $('#J_a') 这个对象 alert($(this).data('name')); }) } choose2()
例子代码: http://codepen.io/hj624608494...
问题出现在 this的指向 this永远指向函数执行时的对象.