简体   繁体   English

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

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

I am working on MVC application and I have jQuery plugin, calculating width and height of page and I am calling this from document.ready function. 我正在MVC应用程序上工作,并且我具有jQuery插件,可计算页面的宽度和高度,并从document.ready函数调用此函数。 I am getting following error 我收到以下错误

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

my plugin 我的插件

(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);

main function 主功能

$(document).ready(function () {

  alert("hello");

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

sometime it alert and sometime it not. 有时它会发出警报,有时则不会。 I have also clear browser cashed and testing this on firefox and jquery version 1.10.2 我也清除了浏览器的现款,并在firefox和jquery 1.10.2版上对此进行了测试

Can you try the same in 'window.onload' event instead of in 'documen.ready' ? 您可以在'window.onload'事件中尝试相同的方法,而不是在'documen.ready'中尝试吗? As, you are trying to refer the window object to get height & width. 如,您正在尝试引用窗口对象以获取高度和宽度。 Unless its not loaded you wont get that value. 除非未加载,否则您将不会获得该值。

Try using code like: 尝试使用如下代码:

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

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

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