0
    switch (selectedRadioVal) {
    case CARD_ORDER_FIELDS:
    case CARD_ORDER_IDS:
        var items = currentSelect.getElementsByTagName("option");
        if (items.length == 0) {
            $('#txtCardOrderField').focus();
            return;
        }
      //something like this:if (CARD_ORDER_FIELDS)do this; else do that;

}

如您所见,如果切换语句的值等于 CARD_ORDER_FIELDS 或 CARD_ORDER_IDS(最后一行除外),我将尝试执行相同的操作。是否可以检查此块内的当前值并根据该值执行部分代码?

4

1 回答 1

2

只需在 switch 中调用 if 语句:

if (selectedRadioVal == CARD_ORDER_FIELDS)
{
   //do something
}

在全:

 switch (selectedRadioVal) {
    case CARD_ORDER_FIELDS:
    case CARD_ORDER_IDS:
        var items = currentSelect.getElementsByTagName("option");
        if (items.length == 0) {
            $('#txtCardOrderField').focus();
            return;
        }
        if (selectedRadioVal == CARD_ORDER_FIELDS)
        {
          //do something
        }    
  }
于 2012-12-05T10:53:40.627 回答