android - jQuery 移动文本字段不会失去焦点

标签 android html cordova jquery-mobile

我是 JQuery mobile 和 Cordova 的新手。我使用 JQuery mobile 创建了一个简单的 Cordova 应用程序,该应用程序具有一个带有简单文本字段和 radio 输入的表单。但是我在运行应用程序时发现了一个问题,因为我输入了一些文本并单击单选按钮,我注意到焦点仍在文本输入上。如果未使用 JQuery mobile,焦点将从文本输入中移出。我知道 JQuery mobile 为这些表单元素添加了一些默认样式。我当我选择单选按钮时,不希望焦点位于文本字段中。请帮助我解决这个问题。我的 HTML 页面代码如下。

<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="css/jquery.mobile-1.4.5.min.css" rel="stylesheet"> 
        <script src="js/jquery-1.11.3.min.js"></script>
        <script src="js/jquery.mobile-1.4.5.min.js"></script>
    </head>
    <body>
        <div>            
            <form>
                <label for="text-basic">Text input:</label>
                <input type="text" name="text-basic" id="text-basic" value="">               
                <fieldset data-role="controlgroup">
                    <legend>Radio buttons, vertical controlgroup:</legend>
                    <input type="radio" name="radio-choice-1" id="radio-choice-1" value="choice-1" checked="checked">
                    <label for="radio-choice-1">Cat</label>
                    <input type="radio" name="radio-choice-1" id="radio-choice-2" value="choice-2">
                    <label for="radio-choice-2">Dog</label>
                    <input type="radio" name="radio-choice-1" id="radio-choice-3" value="choice-3">
                    <label for="radio-choice-3">Hamster</label>
                    <input type="radio" name="radio-choice-1" id="radio-choice-4" value="choice-4">
                    <label for="radio-choice-4">Lizard</label>
                </fieldset>
            </form>
        </div>
    </body>
</html>

下面附上Mobile View的截图。

enter image description here

在上图中,即使我从单选按钮列表中选择一个元素,您也可以看到 Android 键盘没有关闭。

最佳答案

试试这个

$("input:radio").addEventListener('touchstart',function(e) {
     $('input[type=text], textarea').focusout();
});

当输入类型的 radio 被触摸时,它手动从 textarea 或 textinput 移除焦点。

或者试试这个

$("input:radio").addEventListener('touchstart',function(e) {
     $(':focus').blur();
});

关于android - jQuery 移动文本字段不会失去焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35278521/

相关文章:

android - 无法从 ActivityGroup 中的 ListActivity 显示 AlertDialog

javascript - jQuery/HTML : How to use variable within onClick

javascript - 我的混合应用程序在检查包含字符串的 li 元素时不会更改页面

ios - 类型 'URL' 的值没有成员 'URLByAppendingPathComponent'

android - 如何为不同的 productFlavors 使用不同的资源集

android - 具有起始偏移量的 RecyclerView

android - pc端使用wireshark监控安卓手机流量

javascript - HTTP POST 不起作用(可能是一些无法确定的愚蠢错误)

android - 移动应用 ionic 在 SSL 证书过期后停止工作并已更改

android - Phongap config.xml 和 Cordova config.xml 之间有区别吗?