【问题标题】:Ipad + How to prevent the keyboard from popping up on jquery datepickerIpad + 如何防止键盘在 jquery datepicker 上弹出
【发布时间】:2012-05-08 02:30:55
【问题描述】:

我想从我的 Ipad 禁用键盘弹出,所以我做了这样的事情,但这不是我的愿望。

我有一个文本框:

<h:inputText id="txtDate" value="#{myDateController.selected.DOB}"

我尝试使用“只读”属性,但数据无法保存到数据库。 我也用这个: $("#frmEdit\:txtDate").attr("disabled", true) --> 但不行

我在网上搜索并使用此链接应用了我的代码,但它也不行:ipad web application: How do I prevent the keyboard from popping up on jquery datepicker

$(function() {
  //$("#frmEdit\\:txtDate").attr("disabled", true)
    $("#frmEdit\\:txtDate").datetimepicker({
     // showOn: "button"
        showOn: "both",   
        buttonImage: "../images/calendar.png",
        buttonImageOnly: true,
        constrainInput: true,
        showButtonPanel: true,         
        dateFormat: 'dd-M-yy',
        addSliderAccess: true,
        sliderAccessArgs: { touchonly: false },
    onClose: function(dateText, inst){ 
        $(this).attr("disabled", false);
    },
    beforeShow: function(input, inst){
        $(this).attr("disabled", false);
    }
});
});

我的代码有什么问题?或任何其他解决方案? 非常感谢

【问题讨论】:

  • 是的,只设置属性只读,没关系

标签: jquery ipad jquery-ui-datepicker


【解决方案1】:

在 HTML 中有一个选项让你做这种事情:

readonly="true"

将此添加到您的输入字段元素。它会“禁用”输入字段,但在完成某些操作(例如单击它)时仍会触发事件。


查看W3Schools Readonly Attribute了解更多信息。

【讨论】:

  • 上次我已经使用了 readonly="true" 但数据无法保存到数据库
  • 这应该是公认的答案。 disabled 不会触发任何事件,并且不会显示日期选择器。
【解决方案2】:

我就是这样设法解决这个问题的,让浏览器认为用户模糊了输入,所以它在有时间显示之前隐藏了键盘:

$('blabla')
    .datepicker(
    {
        /* options */
    })
    .on('focus',function()
    {
        $(this).trigger('blur');
    });

在我发现的许多其他解决方案没有的地方对我很有效!

【讨论】:

  • readonly 在 iPad (iOS8) 上的 Safari 中无效。这对我来说效果很好,但是每次您点击日历的一部分时,页面都会“跳跃”,因为键盘开始打开然后关闭。
【解决方案3】:

您是否尝试过使用 HTML 禁用输入字段(因此添加 disabled="disabled")?

【讨论】:

  • 是的,我现在可以了。我为我的文本框设置了只读属性: document.getElementById('txtDate').setAttribute("readonly", "true");
  • 并在body调用onload()函数
  • 尚未在我的 Ipad 上使用您的解决方案 disabled="disabled" 进行测试,让我明天试试
【解决方案4】:

正确的答案往往是最简单的。

readonly="true"

解决办法

【讨论】:

  • 这与其他答案相同,但解释更少 - 不要拒绝投票,因为您是 SO 新手,但您应该阅读帮助等 - SO 不是论坛。
猜你喜欢
  • 2011-04-02
  • 1970-01-01
  • 2011-12-01
  • 1970-01-01
  • 2013-01-13
  • 1970-01-01
  • 1970-01-01
  • 2018-07-26
  • 2014-08-24
相关资源
最近更新 更多