我正在尝试添加一个自定义的jquery插件。但是我收到错误jQuery(...)。termifier不是一个函数....我很确定代码中没有错误
为了进行测试,我尝试从learning.jquery.com复制代码
(function($) {
$.fn.greenify = function() {
this.css("color", "green");
return this;
};
}(jQuery));
进而
jQuery('..').greenify();
返回我错误jQuery('..')。greenify不是一个函数
到底是怎么回事???有谁知道原因吗?
编辑
更多代码。绿色化只是为了表明它不适用于标准示例...。
实际的插件...当前放置在同一文件中,以后在ellements上调用它,因此找不到文件的问题。
(function($) {
$.fn.termifier = function(options) {
options = $.extend({
lookupResource: 'getTerm',
flyoutClass: 'lookerUpperFlyout'
},options||{});
this.attr('title','Click me for my definition!');
return this.click(function(event){
$.ajax({
url: options.lookupResource,
type: 'get',
data: {term: this.innerHTML},
dataType: 'html',
success: function(data) {
$('<div></div>')
.css({
position: 'absolute',
left: event.pageX,
top: event.pageY,
cursor: 'pointer',
display: 'none'
})
.html(data)
.addClass(options.flyoutClass)
.click(function(){
$(this).fadeOut(1500,function(){$(this).remove();});
})
.appendTo('body')
.fadeIn();
}
});
return false;
});
};
}(jQuery));
jQuery(document).ready(function(){
...
jQuery('abbr').termifier({
lookupResource: 'some.php'
});
});
我很无知...
首先,确保您使用Joomla的API导入jQuery ,如下所示:
<?php
JHtml::_('jquery.framework');
?>
这将确保仅导入jQuery的1个实例,并且也以noConflict模式导入。
完成后,您应该使用jQuery
全局范围并将其$
用作别名(可选):
jQuery(document).ready(function($){
$.fn.greenify = function() {
this.css("color", "green");
return this;
};
});
希望这可以帮助
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句