javascript - jquery函数调用问题
本文介绍了javascript - jquery函数调用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
jQuery.fff = {
init:function(){
this.b();
},
a:function(){
console.log('a');
},
b:function(){
console.log('b');
$(document).on('click','.btn-primary',function(){
$.fff.a();
});
}
};
$(function(){
$.fff.init();
});
如上JQ代码,在执行 .btn-primary 的点击事件时,报a函数undefined,这是什么问题呢?
解决方案
作用域问题
b:function(){
var This=this;
console.log('b');
$(document).on('click','.btn-primary',function(){
This.a();
});
}
这篇关于javascript - jquery函数调用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文