2012-08-12 52 views
0

我寫了下面的javascript代碼,現在我想添加另一個條件/更改不接受零的現有條件。在下面的代碼中添加另一個條件,不接受'0'

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', ''); 
      } 
+0

我們怎樣才能幫你?改變什麼條件?你需要更具體些。 – Blender 2012-08-12 06:09:00

回答

0
var val = $(".vo_head_spots_available:eq(" + i + ")").val(); 

if(0 != val && "U" != val.toUpperCase() && !onlyNumbers(val)) { 
    // ... 
} else { 
    // ... 
} 
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'); 
}