$.fn.test添加一个方法,在$(function(){})之外可以正常使用,在 $(function(){})里 $().test为undefined
相关代码
//引入js
$.fn.toastmessage = function (method) {
// Method calling logic
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.toastmessage');
}
};
//页面行内script
var $message = $()
$(function () {
console.log($().toastmessage);
console.log($message.toastmessage);
你期待的结果是什么?实际看到的错误信息又是什么?
console.log($().toastmessage); //undefind
console.log($message.toastmessage);//正常 function
为什么在 $(function () {下 jq实例找不到继承的方法