Jquery校验数组中是否存在不同的值

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangtongpeng/article/details/81271264
用的$.inArray
var arr = [ 10, 25, 3, 0, -3 ];

w( $.inArray( 25, arr ) ); // 1
w( $.inArray( -3, arr ) ); // 4
w( $.inArray( 10, arr ) ); // 0

// 数组中没有99
w( $.inArray( 99, arr ) ); // -1
// 数组中有数字10,但是没有字符串"10"
w( $.inArray( "10", arr ) ); //

以下为代码

           var Codes=new Array();
            var ids=new Array();
            var Code;
            var boolean=true;
            //存在某个条件不同的数据时,不能进行下一步
            $('input[name=reqOrder]').each(function() {//遍历所有的复选框
                if ($(this)[0].checked) {//只校验选中的复选框
                  if(Codes.length>0&&$.inArray($(this)[0].value,Codes)==-1){
                      boolean=false;
                      var dialog = Common.alertDialog({
                          title: '错误提示',
                          content: '不同协议的订单不能同时提交!',
                          okValue: '确 定',
                          quickClose:true,
                          ok: function () {

                          },

                      });
                      dialog.showModal();
      }else{//如果数据都相同继续添加
                     Code=$(this)[0].value;
                      Codes.push($(this)[0].value);
                      ids.push($(this).attr("label"))
      }
                }
            })
if(boolean){
                window.location.href="#/pages/checkbiz/pu_statements_ordercarddetail";
                Common.store.set("agreementCode",agreementCode);
                Common.store.set("orderids",orderids);
}

猜你喜欢

转载自blog.csdn.net/zhangtongpeng/article/details/81271264