简体   繁体   English

有没有一种方法可以防止移动键盘出现而又不会阻止桌面输入?

[英]Is there a way to prevent mobile keyboard from showing up without blocking desktop input?

I am using a jquery date picker in my website. 我在我的网站上使用了一个jQuery日期选择器。 (I am using this one currently, but may use other library if necessary) It allows the user to input date using the date picker popup or directly inputting the date using keyboard. (我目前正在使用库,但如有必要,可以使用其他库)。它允许用户使用日期选择器弹出窗口输入日期,或使用键盘直接输入日期。 The problem is this also makes the mobile keyboard popup when the site is viewed on mobile device, and sometimes make the date picker having not enough room for display in smaller device. 问题在于,当在移动设备上查看站点时,这也会使移动键盘弹出,有时使日期选择器没有足够的空间显示在较小的设备中。

I know I can prevent this behavior by adding readonly , disabled or lose focus on click. 我知道我可以通过添加readonlydisabled或使点击失去焦点来防止此行为。 However, this also stops users from inputting through keyboard on desktop. 但是,这也会阻止用户通过台式机上的键盘输入。 Is there a way I can just stop mobile keyboard from showing up? 有什么方法可以阻止移动键盘显示吗?

You can do something like this: 您可以执行以下操作:

var width = jQuery(window).width();
if(width > 768) {
  jQuery("targetelem").attr('readonly', true);
}

Here targetelem is input name. 在这里,targetelem是输入名称。 This is a easy way (there are more sophisticated alternatives) to get started. 这是一种简单的上手方法(有更复杂的替代方法)。

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

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