使用jQuery级联下拉验证

时间:2015-05-11 06:38:09

标签: jquery

我有两个Cascading Drop Downs。下拉1具有值A,B,C。如果选择A,则在下拉2中填充值1,2,3。如果选择B,则填充值6,7,8。

要求:我想验证Cascading Drop Downs,如果在Drop Down 1中选择A,则在Drop Down 2中选择1.它应该是第一次允许。我可以通过单击“添加”按钮添加新行。再次当我在Drop Down 1中选择A时,在Drop Down 2中选择1.在提交/保存点击时不应该允许。请提供一个jQuery脚本来验证这一点。提前谢谢。

function ValidationCascadingDD(){         调试器;

    $('select[id^="ddlApplicableGroup_infrastructure"]').each(
      //start outerloop against each element
      function (index, element) {
          //find all the items again
          $('select[id^="ddlProfileName_infrastructure"]').each(
            //start inner loop on each item
            function (indexInner, elementInner) {
                debugger;
                if (index != indexInner) {
                    //compare the items here as they are not the same index numbers so are different elements
                    //there are different ways to compare, but you could use jquery again for this
                    //and use the element and elementInner to access each of them.
                    if ($(element).val() == $(elementInner).val())

                        alert("2 dd have the same value:" + element.id + ":" + elementInner.id);
                }
            }
         );
      }
    );


}

0 个答案:

没有答案