【发布时间】:2012-02-06 02:43:23
【问题描述】:
我有以下函数,它总是返回 True。任何想法为什么以及如何避免它?谢谢各位。
function validateStatuses(xyx){
var umm = ugh[xyx];
var selects = $('#cont_'+ugh.xyz+' .status_select');
var codes = $('#cont_'+ugh.xyz+' .status_code');
for (var i = 0; i < selects.length; i++) {
var value = selects[i].options[selects[i].selectedIndex].value;
if (value == 'new'){
for (var j = 0; j < codes.length; j++) {
var blagh = codes[j].options[codes[j].selectedIndex].value;
if(blagh == 13){
$('#info_dialog').html('');
$('#info_dialog').append("<p>You are trying to process a bill ("+bill.name+") with a STATUS of NEW and a STATUS CODE of NONE. Please correct this issue before you proceed!</p><hr />");
$('#info_dialog').dialog({
buttons:{
Cancel: function(){
$(this).dialog('close');
}
}
});
billCounterAdd();
return false;
}//end if
}//end for
}else{
return true; //this is the problem;
}//end if
}//end for
}//end Function
【问题讨论】:
-
它返回
true,因为在某些时候,if (value == 'new')将条件评估为false,因此将代码流向else分支。 -
任何时候你必须评论一个块的关闭
"}"这通常意味着这个块太长了。
标签: javascript if-statement return