未捕获的类型错误:无法读取属性'innerText'的未定义
Uncaught TypeError: Cannot read property 'innerText' of undefined
实际上我有两个错误,我不知道第一个是从哪里来的。我包含了来自"code.jQuery.com"的jQuery v.2.1.3,Chrome向我显示了这个错误
未捕获类型错误:无法读取未定义的的属性"innerText"
我想第二个错误是我自己造成的。
<head>
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
</head>
<body>
<div class="mydiv" style="height:500px; width:500px; margin:50px auto; background-color:#ddd;">
</div>
<script type="text/javascript">
(function($) {
$.scrollbar = function(options){
var opts = $.extend($.scrollbar.defaults, options);
};
$.scrollbar.defaults = {
background: "yellow"
};
})(jQuery);
$(function(){
$('.mydiv').scrollbar();
//Error: Uncaught TypeError: undefined is not a function
});
</script>
</body>
有人能帮我吗?我的谷歌技能已经到了极限,很快就要放弃了。
不确定innerText与错误有什么关系,您应该只得到错误"Uncaught TypeError:undefined不是函数"
您制作插件的方式是错误的。这是一个基本的插件结构。注意fn
的使用
(function($) {
$.fn.scrollbar = function(options) {
var opts = $.extend($.fn.scrollbar.defaults, options);
return this.each(function() {
$(this).css("background-color", opts.background);
});
};
$.fn.scrollbar.defaults = {
background: "yellow"
};
})(jQuery);
$(function() {
$('.mydiv').scrollbar();
$('.myOtherDiv').scrollbar({ "background":"red"});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="mydiv">XXXXXXXXXX</div>
<div class="myOtherDiv">XXXXXXXXXX</div>
相关文章:
- 主干中的模型属性未定义
- JavaScript 2d 数组导致“无法读取未定义的属性'未定义'”
- JSON对象属性未定义
- Waypoint的循环,退出循环后属性未定义
- Javascript:错误“无法设置属性”..'未定义”
- 翡翠 - 显示对象属性 - 未定义
- 属性未定义,但控制台.log可以看到它
- JavaScript 对象的属性未定义
- Javascript 对象属性未定义(但属性已设置)
- DOM 元素属性未定义 - jquery / ruby on rails.
- Nodejs JSON 属性未定义
- 错误:窗口打开器的属性未定义
- angular Js:Array.lenght属性未定义
- 正在尝试访问JavaScript对象的属性=未定义
- Marionette属性未定义,请从API获取
- AngularJS作用域属性未定义
- 对象的属性未定义,尽管已指定值
- 为什么我一直收到一个错误,说对象属性未定义
- 对象属性未定义,但我看到它不是
- .map()img src属性未定义