0

我编写了以下 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', '');
             }
4

2 回答 2

0

也许

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');
}
于 2012-08-12T06:10:00.487 回答
0
var val = $(".vo_head_spots_available:eq(" + i + ")").val();

if(0 != val && "U" != val.toUpperCase() && !onlyNumbers(val)) {
    // ...
} else {
    // ...
}
于 2012-08-12T06:12:08.687 回答