2013-12-12 68 views
0

我非常新的角度JS。在這裏我有如下的簡單形式: test3.php:在驗證失敗IE9使用角度JS

<!DOCTYPE html> 
<html ng-app> 
<head> 
    <script src="http://code.angularjs.org/1.2.4/angular.min.js"></script> 
</head> 
<body> 
    <form name="myForm" id="myForm" ng-controller="Register" ng-submit="submit()" action="test2.php" method="post"> 
    <label>First Name:</label> 
    <input type="input" name="firstname" ng-model="firstname" required> 

    <label>Last Name:</label> 
    <input type="input" name="lastname" ng-model="lastname" required> 

    <label>Email:</label> 
    <input type="email" name="email" ng-model="email" required> 

    <input type="submit" id="submit" value="Submit" /> 

</form> 
    <script> 

    function Register($scope) { 
    $scope.firstname = ''; 
    $scope.lastname = ''; 
    $scope.email = ''; 
    $scope.submit = function() { 
     document.getElementById('myForm').submit(); 
    }; 
    } 
    </script> 
    </body> 
    </html> 

而且test2.php:

<?php 
     echo $_POST['firstname']; 
?> 

當我加載test3.php並點擊提交而沒有填寫任何細節時,我收到消息填寫相應的字段,表單不提交到test2.php。當所有的細節輸入正確,然後如果我點擊提交,我看到$_POST['firstname]值。這適用於Chrome和Firefox。

但在IE9中,根本沒有驗證。點擊提交後,表單會一直提交,無論字段是否爲空。

如何讓此代碼在IE9中工作? Angular JS API爲IE 8或更低版本提供幫助。

回答

3

的原因是由於這樣的事實,即(IE < 10)不符合HTML5相對於客戶端驗證,並且因此不會如果"required"屬性是存在於輸入元件上返回true,而是返回(string)屬性值。使用ngRequired代替required屬性。

+1

感謝您的回覆。我按照你的建議嘗試了'ngRequired',但它也沒有工作。 –

+2

您需要自行爲IE編寫驗證< –

+0

是的。情況正在呼喚它。 :(Thanks thanks any。 –