简体   繁体   English

防止键盘在iPad webapps上弹出文本框焦点/单击

[英]Prevent keyboard from popping on textbox focus/click in iPad webapps

I am trying to create a custom keyboard on an iPad application. 我正在尝试在iPad应用程序上创建自定义键盘。 But each time the input get the focus, the native iPad keyboard pops up. 但每次输入获得焦点时,弹出原生iPad键盘。 How can I prevent this, in JavaScript. 我怎样才能在JavaScript中阻止这种情况。

将属性“readonly”添加到输入中,并提供填充值的不同方法。

I don't think you can prevent the keyboard from appearing on input fields. 我认为你不能阻止键盘出现在输入字段上。 However you could create an html element that looks just like an input field with CSS and handle the onClick event to show your custom keyboard. 但是,您可以创建一个html元素,它看起来就像一个带CSS的输入字段,并处理onClick事件以显示您的自定义键盘。

<style>
    .textField{
        width: 120px;
        height: 17px;
        border-style:inset;
        border-width: 2px;
        border-color: gray;
        float: left;
    }
</style>
<script>
    function showKeyboard(){
        alert("show the my cool keyboard");
    }
</script>

Name: <div onClick="showKeyboard()" class="textField"></div>

You should checkout Sencha Touch for developing Web Apps for iOS devices. 您应该检查Sencha Touch以开发适用于iOS设备的Web应用程序。

position an absolute div with a z-index:1 on top of the text input field, and attach an onclick handler to the div that launches the keypad. positionabsolute divz-index:1的文本输入框的顶部,并附加onclick处理程序的div会启动键盘。

Next step would be to attach the keypad numbers to affect the value of the text field. 下一步是附加小键盘数字以影响文本字段的值。

The best thing to do is to stop the event on the onclick event. 最好的办法是在onclick事件上停止事件。
html : HTML:

<textarea onclick='myOnClickEvent'></textarea>

Javascript : Javascript:

function myOnClickEvent(e){
e.stopPropagation();
}

Dojo : 道场:

function myOnClickEvent(e){
dojo.stopEvent(e);
}

Sencha : Sencha:

function myOnClickEvent(e){
e.stopEvent();
}

I hope this help. 我希望这有帮助。

仅供参考,您也可以在输入上调用blur()来隐藏键盘......虽然在这种情况下可能不是一个好的解决方案。

我们有完全相同的问题所以我们使用以下代码。它工作

<input type="text" onclick="openAlphaNumKeyboard(this)" onfocus="blur()" id="test-input" />

You should check the safari sdk , there are some extra input types available with mobile safari/html5. 您应该检查safari sdk ,还有一些额外的输入类型可用于移动safari / html5。

Otherwise you could style a div/span to look like an input and have a backing hidden field, then when it is clicked on bring up your custom div etc and put values into the "input" based on the users actions. 否则,您可以将div / span设置为看起来像输入并具有后备隐藏字段,然后在单击它时调出自定义div等,并根据用户操作将值放入“输入”。

Of course you would do this with progressive enhancement and render this as a normal textbox then on the loading of the page swap the normal text input for your hidden field/div/span etc 当然你会用渐进增强来做这个并将它渲染为普通文本框然后在加载页面时交换隐藏字段/ div / span等的普通文本输入

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM