繁体   English   中英

Chrome中的控制台错误:window.function不是功能

[英]Console Error in Chrome: window.function is not a function

在chrome中,我的JS收到以下错误:

Uncaught TypeError: window.picturefill is not a function

我该如何解决?

function activateVisiblePicturefills() {
    jQuery("span").each(function(i, elm) {
        var $elm = jQuery(elm);

        if (checkvisible($elm)) {
            var content = $elm.html(),
                $pic = jQuery("<picture id=" + $elm.attr("id") + ">" + content + "</picture>").addClass($elm.attr("class")),
                pic = $pic[0];

            $elm.after($pic);  // insert the picture
            $elm.remove();     // remove the span

            window.picturefill({ elements: [ pic ] });
        }
    });
}

如果您包含了picturefill.js脚本,则该脚本位于全局名称空间中

而不是打电话

window.picturefill()

只是打电话

picturefill();

一般而言,全局名称空间是窗口对象,在浏览器中作为标准对象调用时,但这是例外。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM