繁体   English   中英

从document.ready调用jQuery插件抛出getPreventDefault错误

[英]Calling jQuery plugin from document.ready throw getPreventDefault error

我正在MVC应用程序上工作,并且我具有jQuery插件,可计算页面的宽度和高度,并从document.ready函数调用此函数。 我收到以下错误

ReferenceError: getPreventDefault is not defined MyCustomScript:1:115
Use of getPreventDefault() is deprecated.  Use defaultPrevented instead. jquery-1.10.2.js:5389:0
no element found

我的插件

(function($) {

$.fn.adjustOuterStripLayout = function () {

    alert("strip");

    $(window).bind('load resize', function () {

        var viewport_height = $(window).height();

        var viewport_width = $(window).width();

        var webPage_containerWidth = $('.container').width();

        alert("viewport_width  " + viewport_width + "container " + webPage_containerWidth);

    });
 };
})(jQuery);

主功能

$(document).ready(function () {

  alert("hello");

 $(this).adjustOuterStripLayout();
});

有时它会发出警报,有时则不会。 我也清除了浏览器的现款,并在firefox和jquery 1.10.2版上对此进行了测试

您可以在'window.onload'事件中尝试相同的方法,而不是在'documen.ready'中尝试吗? 如,您正在尝试引用窗口对象以获取高度和宽度。 除非未加载,否则您将不会获得该值。

尝试使用如下代码:

$(window).load(function () {  
 $(this).adjustOuterStripLayout();  
});

暂无
暂无

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

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