鍍金池/ 問答/物聯(lián)網(wǎng)  網(wǎng)絡安全  HTML/ [求助]基于Cordova InAppBrowser的APP在iPad中運行時軟

[求助]基于Cordova InAppBrowser的APP在iPad中運行時軟鍵盤沒法在特定條件下被focus()彈出的問題

用Angular5.2.9 + Ionic3.2 + Ionic Native 4.5.3 + Cordova8.0 + Cordova-ios 4.5.4 + Cordova-plugin-inappbrowser 2.0.3-dev 做了一個帶有InAppBrowser的APP,在APP中訪問如下html,運行后效果 以及 代碼如下:

n89gP.png

testsoftkeyboard3.html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Expires" content="0">
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script language="javascript">
    var objInput1=null;
    var objInput2=null;

    function initLoad()
    {
        objInput1=document.getElementById("input1");
        objInput2=document.getElementById("input2");
    }

    function onBlur(event)
    {
        if(event.target.value == 'abc')
        {
            event.target.style.backgroundColor="#ffffff";
            return true;
        }

            //這里如果不用setTimeout來執(zhí)行alert,那么當采用下面描述的方式2時,整個InAppBrowser會死掉,不想應任何操作
            setTimeout(function () {
                alert('please input abc');
                //objInput1.focus();
                //objInput1.click();
            }, 0);  

        event.target.style.backgroundColor = "#ff0000";
        event.target.focus();
        event.target.click();

        return false;
    }

</script>
</head>
<body onload="javascript:initLoad()">
input1:<input type="text" id="input1" onblur="javascript:onBlur(event);"/>&nbsp&nbsp&nbsp&nbsp - &nbsp&nbsp&nbsp&nbsp
input2:<input type="text" id="input2"/>
<br/>
</body>
</html>

上面的代碼主要是為了實現(xiàn)以下效果:

第1步、當焦點在input1中時,iPad自動顯示軟鍵盤(代碼上沒有特意控制,應該是iOS 默認的功能,焦點在輸入框時會自動彈出軟鍵盤)

kC96b.png

第2步、當在input1中輸入內(nèi)容后,在失去焦點時進行輸入檢查(在onblur事件中實現(xiàn)),如果發(fā)現(xiàn)輸入的內(nèi)容不為abc,則彈出alert警告

uEuSi.png

第3步、同時將input1的背景色改為紅色,并且讓焦點回到input1,并自動顯示出軟鍵盤

tHqNb.png

目前遇到的問題主要出在上面第2步與第3步,讓input1失去焦點有兩種方式:
方式1、點擊input2
方式2、按軟鍵盤最右下角的按鈕將鍵盤收起
NY1AN.png

目前按方式1來操作,沒有問題,第3步能按照預期的效果呈現(xiàn)。
但是當采用方式2時,當通過調(diào)用focus()方法讓input1獲得焦點后,軟鍵盤會閃現(xiàn)(出現(xiàn)后,又馬上消失),試了很多方法都能保持軟鍵盤一直出現(xiàn),調(diào)查了2,3天都沒搞定,不知道是否需要修改InAppBrowser的Objective-C代碼,麻煩大家?guī)兔匆幌聭撛鯓咏鉀Q?非常感謝!

回答
編輯回答
陌璃

有什么辦法可以主動控制(比如通過代碼)讓軟件盤彈出 或者 收起嗎?

2018年3月3日 21:44