获取未定义值的jQuery插件

时间:2018-02-26 20:30:26

标签: jquery jquery-plugins

我正在学习如何创建自己的jQuery插件,而且我遇到了一个问题,我不知道为什么会看到它。这是我的插件:

(function($){
    $.fn.clipping = function() {
        console.log("Offset Width: " + this.offsetWidth);
        console.log("Scroll Width: " + this.scrollWidth);

        if(this.offsetWidth > this.scrollWidth) {

        } else {

        }
    };
})( jQuery );

然后在文档加载中我有这个:

$("#tiles").clipping();

在控制台中我得到了这个:

Offset Width: undefined
Scroll Width: undefined

为什么会这样?我是否需要做一些事情以确保它按照我想要的ID查看确切的元素?

0 个答案:

没有答案