Javascript 未捕获类型错误:对象[对象对象]没有方法';边界';?
这个错误快把我逼疯了!无论如何,我创建了一个简单的jQuery插件,我称之为“border”,但我得到了以下错误: 未捕获类型错误:对象[Object Object]没有方法“border” 作为记录,jQuery只包含一次,并且它包含在我的插件之前 我用它来避免冲突:Javascript 未捕获类型错误:对象[对象对象]没有方法';边界';?,javascript,jquery,plugins,Javascript,Jquery,Plugins,这个错误快把我逼疯了!无论如何,我创建了一个简单的jQuery插件,我称之为“border”,但我得到了以下错误: 未捕获类型错误:对象[Object Object]没有方法“border” 作为记录,jQuery只包含一次,并且它包含在我的插件之前 我用它来避免冲突: <pre> var $jq = $.noConflict(); //$.noConflict(); $jq("li").borderX('1px solid blue'); </pre> 我从中调用名为
<pre>
var $jq = $.noConflict();
//$.noConflict();
$jq("li").borderX('1px solid blue');
</pre>
我从中调用名为“borderX”的插件的HTML代码是:
删除插件的第一行和最后一行,这样它就不会被包装在
文档中。就绪
那么你如何设置你的插件呢?请发布你的名为“border”的插件,你正在调用
borderX
method。我实际上已经将名称更改为“borderX”,我得到了相同的错误。我一直在调用“borderX”。错误不在上面的代码中,而是在你的插件中。我们可以看看代码吗?你没有从插件中提供一盎司代码。我突然想到两件事——你没有加载插件,或者你没有向jQuery公开你的插件,因此如果jQuery没有“看到”它,这个方法就不存在了。我看到了,但实际上,我遇到了另一个错误。似乎无法识别“extend”:未捕获的TypeError:无法调用UndefinedAllRight的方法“extend”,现在我使用了:$jq(“li”).border({width:'2px',color:'red',radius:'1px');它会生成相同的错误:Uncaught TypeError:无法调用UndefinedTo的方法“extend”。其他地方一定有冲突,因为我可以将代码复制并粘贴到此页面上的控制台中,并在没有错误的情况下运行该代码,并为所有内容添加边框(我修复了上面的代码中的一个输入错误-我删除了每个样式属性后面的:
)这很奇怪:(我仍然得到这个:Uncaught TypeError:无法调用未定义的jquery.border.js:3$.fn.border jquery.border.js:3(匿名函数)events.html:19(匿名函数)这正是我的jquery.border.js文件!
jQuery(document).ready(function ($) {
$.fn.borderX = function (params) {
params = $.extend({width: 'null', color: 'null', radius: 'null'}, params);
this.each(function () {
var $t = $(this);
var response = jQuery.parseJSON(params);
if (typeof response == 'object') { //It is JSON
if (params.width) {
$t.css('border-width:', params.width);
}
if (params.color) {
$t.css('border-color:', params.color);
}
if (params.radius) {
$t.css('border-radius:', params.radius);
}
} else {
$t.css('border', params);
}
});
return this;
};
});
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="jquery.borderX.js"></script>
<script type="text/javascript">
var $jq = $.noConflict();
//$.noConflict();
$jq("li").borderX('1px solid blue');
</script>
$.fn.border = function (options) {
var params = $.extend({width: 'null', color: 'null', radius: 'null'}, options);
this.each(function () {
var $t = $(this);
var response = jQuery.parseJSON(params);
if (typeof response == 'object') { //It is JSON
if (params.color) {
$t.css('border-color:', params.color);
}
if (params.radius) {
$t.css('border-radius:', params.radius);
}
} else {
$t.css('border', params);
}
});
return this;
};
(function($) {
$.fn.borderX = function(params) {
params = $.extend( {width: 'null', color: 'null', radius: 'null'}, params);
this.each(function() {
var $t = $(this);
var response = jQuery.parseJSON(params);
if(typeof response == 'object')
{ //It is JSON
if(params.width){$t.css('border-width',params.width);}
if(params.color){$t.css('border-color',params.color);}
if(params.radius){$t.css('border-radius',params.radius);}
}
else
{
$t.css('border',params);
}
});
return this;
};
})(jQuery);