在$ .mobile中覆盖JQuery Mobile方法的正确方法

我正在研究的JQuery Mobile应用程序在软键盘启动时往往会吓坏。 我已经实现了一个解决方案并且效果很好,但是我必须直接编辑jquery.mobile-1.2.0.js来完成它。 我更愿意将我的更改保存在jquery.mobile.customizations.js文件中,该文件扩展了jQuery Mobile。

我试图做以下事情但没有成功:

delete $.mobile.getScreenHeight; $.mobile.last_width = null; $.mobile.last_height = null; $.mobile.getScreenHeight = function() { // My modified version } 

我在$.mobile.getScreenHeight添加了alert语句,加上原来的$.mobile.getScreenHeight 。 我确实看到我的自定义方法的警报被触发,但有时,它也会触发原始函数中的警报。

有没有人知道在$ .mobile中覆盖方法的正确方法,还添加了两个新属性?

(有关原始问题的完整详细信息在window.resize中,因虚拟键盘导致jquery mobile出现问题 )

更新:

@elclanrs – 我试图在没有运气的情况下实现下面的代码。 我也尝试过交换第二个和第三个参数。 每当我运行代码时,它会触发我的扩展getScreenHeight,但它会触发基本的getScreenHeight。 (我掏空了原来的getScreenHeight并在里面发出警报。警告永远不应该开火。

开放思想!

 $.mobile = $.extend( {}, $.mobile, { last_width: null, last_height: null, getScreenHeight: function() { // My code... } } ); 

违规行似乎是一个getScreenHeight = $.mobile.getScreenHeight; 它将当前定义放在resetActivePageHeight函数的闭包中。 我不确定是否可以在不编辑文件的情况下直接覆盖它,但您可能能够在下游关闭它:

  //simply set the active page's minimum height to screen height, depending on orientation function resetActivePageHeight() { var aPage = $( "." + $.mobile.activePageClass ), aPagePadT = parseFloat( aPage.css( "padding-top" ) ), aPagePadB = parseFloat( aPage.css( "padding-bottom" ) ), aPageBorderT = parseFloat( aPage.css( "border-top-width" ) ), aPageBorderB = parseFloat( aPage.css( "border-bottom-width" ) ); aPage.css( "min-height", getScreenHeight() - aPagePadT - aPagePadB - aPageBorderT - aPageBorderB ); } //set page min-heights to be device specific $( document ).bind( "pageshow", resetActivePageHeight ); $( window ).bind( "throttledresize", resetActivePageHeight ); 

定义你自己的resetActivePageHeight然后unbind并再次bind它们可能会成功。 这有点乱。