2014-03-29 40 views
1

我試圖找出它爲什麼不爲我工作,下面的代碼必填字段HTML 5不要在Android上的Web瀏覽器

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>myTestForm</title> 
</head> 
<body> 
<form action="ok" method="post" id="myform"> 
<p> 
<input name="user_name" type="text" required id="user_name"> 
</p> 
<p> 
<input name="user_password" type="password" required id="user_password"> 
</p> 
<input name="sumbit" type="submit" id="sumbit" value="send"> 
</form> 
</body> 
</html> 

我嘗試使用Chrome或Android海豚瀏覽器進行測試工作,但它確實不工作 它只適用於普通電腦在大多數瀏覽器中

任何人都知道它爲什麼不起作用?有沒有辦法解決這個問題

回答

1

要求屬性只適用於Android版本< 2.3。

http://www.wufoo.com/html5/attributes/09-required.html

基本的JavaScript使用jQuery驗證:

$('[required]').on('blur', function() { 
    if (!$(this).val().length) { // check if the value is empty 
     // Could do an alert or something else 
    } 
}); 
+0

什麼是要解決,否則 – manny

+0

你可以使用JavaScript驗證庫或使自己的JavaScript驗證(見在回答更新)的最佳方式。或者你可以在服務器上做這個驗證。 –

+0

謝謝您的建議 – manny