我正在使用的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