zoukankan      html  css  js  c++  java
  • js判断数组是否包含指定元素的方法

    通过prototype定义了数组方法,这样就可以在任意数组调用contains方法

    Array.prototype.contains = function ( needle ) {
      for (i in this) {
        if (this[i] == needle) return true;
      }
      return false;
    }

    例子:

    var x = Array();
    if (x.contains('foo')) {
      // do something special
    }

    angularjs运用:

    $watch监控"dataList.car_type"的值变化
        $scope.carList = false;
        $scope.$watch("dataList.car_type", function (newValue, oldValue) 
        {
            if ($scope.dataList.car_type.contains('car') ) {
                $scope.carList = true;
            }
           
            if($scope.dataList.car_type.length !=0) {
                $(".personInput").css("color","#9e9e9e");
                $(".personInput input").attr("disabled","disabled");
            }else {
                $(".personInput").css("color","#444444");
                $(".personInput input").removeAttr("disabled");
            }
        },true);
  • 相关阅读:
    2019年4月18日 查询功能 2
    bzoj3601
    bzoj2693
    bzoj2440
    bzoj3529
    bzoj2820
    BZOJ2813
    BZOJ4515
    AtCoder Grand Contest 001 题解
    BZOJ2757
  • 原文地址:https://www.cnblogs.com/miny-simp/p/8709255.html
Copyright © 2011-2022 走看看