我正在开发 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();
});
关于javascript - 从 document.ready 调用 jQuery 插件抛出 getPreventDefault 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29028177/