簡體   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