Javascript 需要简单代码的解释吗
什么意思Javascript 需要简单代码的解释吗,javascript,jquery,Javascript,Jquery,什么意思 isNullOrEmptyById的功能如下: if(!CommonUtil.isNullOrEmptyById('startDt')) { cnt++; } 但是什么呢 isNullOrEmptyById: function(id) { var value = this.getTrimValueById(id); return this.isNullOrEmpty(value); }, 你在这里干什么?其实没必要。因为cnt的值为0或1时才递增。相反,您
isNullOrEmptyById
的功能如下:
if(!CommonUtil.isNullOrEmptyById('startDt')) {
cnt++;
}
但是什么呢
isNullOrEmptyById: function(id) {
var value = this.getTrimValueById(id);
return this.isNullOrEmpty(value);
},
你在这里干什么?其实没必要。因为cnt的值为0或1时才递增。相反,您可以摆脱所有这些,使用isNullOrEmptyById函数
cnt++;
if(!CommonUtil.isNullOrEmptyById('startDt')){
CommonUtil.setFocusById('srchWord','');
返回false;
}
这只是一个如果
条件块:
if(!CommonUtil.isNullOrEmptyById('startDt')){
CommonUtil.setFocusById('srchWord','<spring:message code="confirm.input" arguments="XXXX"/>');
return false;
}
因此,如果CommonUtil.isNullOrEmptyById('startDt')
解析为false
,则条件解析为true
,并执行块中的代码:
if(!CommonUtil.isNullOrEmptyById('startDt')) {
cnt++;
}
增加值。因此,cnt
中的数值将增加1
但是,在代码的整体上下文中,似乎将
cnt
视为一个布尔值而不是整数。除非本例之外还有更多代码,否则可以通过对最后一个条件块使用此条件而不是使用cnt
,然后检查其值来简化此过程。递增计数器?因此根据代码,如果StartDt不是Null或空,cnt递增为1,对吗?如果是Null或空,cnt保持为0。那么春天的消息发生了吗?
if(!CommonUtil.isNullOrEmptyById('startDt')) {
cnt++;
}
cnt++;