Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/426.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要简单代码的解释吗_Javascript_Jquery - Fatal编程技术网

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++;