简体   繁体   English

html5必需的验证在浏览器上工作得很好,但在phonegap应用程序上却不能

[英]html5 required validation working great on browser but not phonegap app

I am developing an app on phonegap (v 5.1.1) and using phonegap app for testing locally on android. 我正在开发phonegap(v 5.1.1)上的应用程序,并使用phonegap应用程序在android上进行本地测试。 I have created a form in html and for validation purpose I've used required property. 我在html中创建了一个表单,出于验证目的,我使用了必填属性。 In browser (firefox, chrome) it is working fine as it should be, while on mobile it does not validate anything. 在浏览器(firefox,chrome)中,它可以正常工作,而在移动设备上,它不进行任何验证。 and submits. 并提交。 Why is this happening ? 为什么会这样呢? Does html5 required supported on android. Android是否需要html5支持。

  <form id="LoginForm" action=""> <input type="email" name="email" id="inputEmail3" placeholder="Email" required> <input type="password" name="pwd" id="inputPassword3" placeholder="Password" required> <button type="submit">Sign in</button> </form> 

Thanks. 谢谢。

You're running Android 4.2.2 and "required" / form validation isn't properly supported there until newer versions of Android. 您正在运行Android 4.2.2,并且在更高版本的Android之前,此处未正确支持“必需” /表单验证。 caniuse.com has a good matrix of support here . caniuse.com 在这里有很好的支持矩阵

To cover all Android versions, you can use "required" but don't rely on it and also defensively code for missing values in your JavaScript when the user submits the form. 为了涵盖所有Android版本,您可以使用“ required”,但不要依赖它,并且可以在用户提交表单时为JavaScript中的缺失值进行防御性编码。

An interesting situation for iOS: now it is supported in Safari Mobile and when used with "Add to Home Screen" feature, however, once the app is built using Cordova, validation is just ignored . 对于iOS而言,一个有趣的情况是:现在Safari Mobile支持它 ,当与“添加到主屏幕”功能一起使用时,但是,一旦使用Cordova构建该应用程序,就将忽略验证

Tested for required attribute, same device, almost the same navigator.userAgent : 测试required属性,相同设备,几乎相同的navigator.userAgent

Browser navigator.userAgent : 浏览器navigator.userAgent

Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0 Mobile/15C107 Safari/604.1 Mozilla / 5.0(iPhone; CPU iPhone OS 11_2,例如Mac OS X)AppleWebKit / 604.4.7(KHTML,例如Gecko)版本/11.0移动版/ 15C107 Safari / 604.1

Cordova app navigator.userAgent : Cordova应用程序navigator.userAgent

Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) Mobile/15C107 Mozilla / 5.0(iPhone; CPU iPhone OS 11_2,例如Mac OS X)AppleWebKit / 604.4.7(KHTML,例如Gecko)移动设备/ 15C107

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

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