我正在使用的JQuery Mobile应用程序在软键盘启动时往往会吓倒。我提出了一个解决方案,它工作的很好,但我不得不直接编辑jquery.mobile-1.2.0.js来完成它。我宁愿将我的更改保存在扩展jQuery Mobile的jquery.mobile.customizations.js文件中。
我试图做没有成功如下:
delete $.mobile.getScreenHeight;
$.mobile.last_width = null;
$.mobile.last_height = null;
$.mobile.getScreenHeight = function()
{
// My modified version
}
我加入警报陈述了我的$.mobile.getScreenHeight
,加上原来的$.mobile.getScreenHeight
。我确实看到我的自定义方法的警报被解雇,但有时它也会触发原始函数中的警报。
有谁知道正确的方式来覆盖$ .mobile中的方法,并且还添加了两个新的属性?
(约原来的问题全部细节都在window.resize due to virtual keyboard causes issues with jquery mobile)
更新:
@elclanrs - 我已经试过,没有运气来实现下面的代码。我也尝试交换第二个和第三个参数。每当我运行代码时,它会激发我的扩展getScreenHeight,但随后它会激发getScreenHeight基础。 (我掏空原getScreenHeight并把警报内。该警报不应该这样火。
公开赛的想法!
$.mobile = $.extend({}, $.mobile, {
last_width: null,
last_height: null,
getScreenHeight: function() {
// My code...
}
});
我找不到'last_width'和'last_height'通过查看源代码,但覆盖'getScreenHeight'就像应该工作... – elclanrs
是的,抱歉 - 澄清,我添加了last_width和last_height属性,并且我想重写getScreenHeight()。然而,我试过的方法,如上所示,并没有像预期的那样工作。它激发了我的自定义功能和原始功能。 – Anthony
您不需要删除它就可以覆盖它。用'.extend'替代$'.extend({getScreenHeight:function(){...}},$ .mobile)' – elclanrs