向以下代码添加不接受“0”的另一个条件

adding another condition to the following code for not accepting '0'

本文关键字:另一个 条件 不接受 代码 添加      更新时间:2023-09-26

我写了下面的javascript代码,现在我想添加另一个条件/更改不接受零的现有条件。

  if ( !onlyNumbers($(".vo_head_spots_available:eq(" + i + ")").val())&& $(".vo_head_spots_available:eq(" + i + ")").val().toUpperCase()!="U")
             {
                   $('#msg_f').html('Please enter the # spots available for your Participants. If unlimited, enter U.').show();
                   $(".vo_head_spots_available:eq(" + i + ")").css('background-color', '#fdd');
                                                        isValid = false;
             }
      else
             {
                  $(".vo_head_spots_available:eq(" + i + ")").val($(".vo_head_spots_available:eq(" + i + ")").val().toUpperCase());
                  $('#msg_f').html('').hide();
                  $(".vo_head_spots_available:eq(" + i + ")").css('background', '');
             }
var val = $(".vo_head_spots_available:eq(" + i + ")").val();
if(0 != val && "U" != val.toUpperCase() && !onlyNumbers(val)) {
    // ...
} else {
    // ...
}

也许

var spots = $(".vo_head_spots_available:eq(" + i + ")");
var val = spots.val.toUpperCase();
if (val =="U" || (onlyNumbers(val) && val !=0)) {
  $('#msg_f').html('').hide();
  spots.css('background', '');
}
else {    
  $('#msg_f').html('Please enter the # spots available for your Participants. If unlimited, enter U.').show();
  spots.css('background-color', '#fdd');
  isValid = false;
}

甚至

var spots = $(".vo_head_spots_available:eq(" + i + ")");
var val = spots.val.toUpperCase();
var isValid = val =="U" || (onlyNumbers(val) && val !=0);
if(isvalid) {
  $('#msg_f').html('').hide();
  spots.css('background', '');
}
else {    
  $('#msg_f').html('Please enter the # spots available for your Participants. If unlimited, enter U.').show();
  spots.css('background-color', '#fdd');
}
相关文章: