简体   繁体   English

使用电子邮件键盘以HTML格式在手机上输入

[英]Use email keyboard for input on mobile in html form

I've got a form with email field. 我有一个带有电子邮件字段的表格。 I'd like it to use email keyboard on mobile browsers. 我希望它在移动浏览器上使用电子邮件键盘。 Now, this is typically done by changing type: <input type="email"/> . 现在,通常通过更改类型来完成: <input type="email"/> However, when I do so, in the desktop Firefox and Chrome the field will be validated by browser. 但是,当我这样做时,在桌面Firefox和Chrome中,该字段将由浏览器验证。 This breaks layout (in Firefox) and supersedes my own validation - which is then visible on all form fields except the email one (this is in Chrome). 这会破坏布局(在Firefox中),并取代我自己的验证-然后,该验证将在除电子邮件地址(在Chrome中是电子邮件地址)之外的所有表单字段上可见。

Is there another way to switch the keyboard to email on mobile, or is there a way to disable validation in desktop browsers? 是否有另一种方法可以将键盘切换为移动设备上的电子邮件,或者可以禁用台式机浏览器中的验证?

You could check if user is not browsing with mobile device, and then add novalidate to input field. 您可以检查用户是否不在使用移动设备浏览,然后将novalidate添加到输入字段。

if(!( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) )) { 
    $('#id').attr('novalidate', 'novalidate');
}

Also if you use this method keep this in your mind: 另外,如果您使用此方法,请记住以下几点:

"User agent sniffing is a very noddy detection technique, user agent strings are a constant moving target, they should not be trusted alone." “用户代理嗅探是一种非常简单的检测技术,用户代理字符串是一个不断变化的目标,不应单独信任它们。” What is the best way to detect a mobile device in jQuery? 在jQuery中检测移动设备的最佳方法是什么?

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

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