angularJS提供输入框不同状态下的样式绑定

输入框有4种状态

ng-model 指令可以为应用数据提供状态值(invalid, dirty, touched, error):

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

    <style>
        input.ng-invalid {
            background-color: lightblue;
        }
    </style>
    <script src="http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></script>
</head>
<body>

    <form ng-app="" name="myForm">
        Email:
        <input type="email" name="myAddress" ng-model="text" required>
        <span ng-show="myForm.myAddress.$error.email">不是一个合法的邮箱地址</span>
        
    </form>



</body>
</html>

 效果 angularJS 状态样式绑定angularJS 状态样式绑定

 ng-show是一个bool值 里面可以是js代码 返回true则显示这个span标签

相关文章:

  • 2021-09-25
  • 2021-12-26
  • 2021-06-12
  • 2022-02-23
  • 2021-09-08
  • 2021-07-10
  • 2022-01-08
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-08-07
  • 2021-12-15
  • 2021-12-09
  • 2022-12-23
相关资源
相似解决方案