采用了棱角分明的JS在IE9验证失败 [英] Validation failing in IE9 using angular js

查看:110
本文介绍了采用了棱角分明的JS在IE9验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty新角JS。在这里我有如下一个简单的表格:
test3.php:

I am pretty new to Angular JS .Here I have a simple form as below: test3.php:

<!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 ['名字] 值。这正常工作在Chrome和Firefox。

When I load test3.php and click on submit without filling any details, I get the message to fill the fields accordingly and the form is not submitted to test2.php. When all the details are entered properly and then if I click Submit, I see the $_POST['firstname] value. This works correctly in chrome and firefox.

但在IE9中,有没有验证的。上点击提交,表单总是提交,是场空。

But in IE9, there is no validation at all. On click of Submit, the form is submitted always, be the fields empty or not.

我如何在IE9这个code的工作,并进一步?该角JS API提供帮助的IE版本8少了。

How do I make this code work in IE9 and further? The Angular JS API provides help for IE versions 8 and less.

推荐答案

的原因是由于一个事实,即(即小于10)不是 HTML5 符合对于客户端验证,因此不会如果需要属性是present输入返回true元素,而是返回(串)属性值。

The cause is due to the fact that (IE < 10) are not HTML5 compliant with respect to client-side validation and therefore wont return true if a "required" attribute is present on the input element, but instead return the (string) attribute value.

使用 ngRequired 而不是要求属性。

这篇关于采用了棱角分明的JS在IE9验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆