从 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();
});
有时它提醒,有时它不。我还清除了浏览器兑现并在火狐和 jquery 版本 1.10.2 上对此进行了测试
你能在'window.onload'事件中尝试同样的方法,而不是在'doccumen.ready'中吗?因为,您正在尝试引用窗口对象以获取高度和宽度。除非它没有加载,否则你不会得到那个值。
尝试使用以下代码:
$(window).load(function () {
$(this).adjustOuterStripLayout();
});
相关文章:
- 没有找到相关文章