如何在javascript中检查null?
我只想根据值执行一个警报框,但空值检查不起作用如何在javascript中检查null?,javascript,jquery,spring-mvc,Javascript,Jquery,Spring Mvc,我只想根据值执行一个警报框,但空值检查不起作用 我的两个警报框都被执行了,这是我的主要问题。我不明白为什么。您所有的值都是字符串,因为您将它们放在引号中: var someValue1 = '${requestScope.someValue}'; var someValue = '${requestScope.someValue}'; var someValue = '${requestScope.someValue}'; if(someValue1 !== null &
我的两个警报框都被执行了,这是我的主要问题。我不明白为什么。您所有的值都是字符串,因为您将它们放在引号中:
var someValue1 = '${requestScope.someValue}';
var someValue = '${requestScope.someValue}';
var someValue = '${requestScope.someValue}';
if(someValue1 !== null && someValue1 !== undefined && someValue1 !== '' && someValue1!=='null'){
alert('Your New someValue1 = '+someValue1);
};
if(someValue !== null && someValue !== undefined && someValue !== '' && someValue!=='null' ){
alert('Error : ' + someValue +"\nDescription : " + someValue);
};
因此,它们永远不会是==null
或==undefined
。此外,除非你有什么东西在处理那些你没有显示的东西,否则它们也永远不会是='
,因为它们是文本字符串{$requestScope.someValue}
(就像'foo'
是文本字符串foo
)
如果要检查值,请检查值本身,
requestScope.someValue
所有值都是字符串,因为您已将它们放在引号中:
var someValue1 = '${requestScope.someValue}';
var someValue = '${requestScope.someValue}';
var someValue = '${requestScope.someValue}';
if(someValue1 !== null && someValue1 !== undefined && someValue1 !== '' && someValue1!=='null'){
alert('Your New someValue1 = '+someValue1);
};
if(someValue !== null && someValue !== undefined && someValue !== '' && someValue!=='null' ){
alert('Error : ' + someValue +"\nDescription : " + someValue);
};
因此,它们永远不会是==null
或==undefined
。此外,除非你有什么东西在处理那些你没有显示的东西,否则它们也永远不会是='
,因为它们是文本字符串{$requestScope.someValue}
(就像'foo'
是文本字符串foo
)
如果要检查该值,请检查该值本身,
requestScope.someValue
可能的重复项您是否有某种方法处理这些{$requestScope.someValue}'
字符串文字?因为在上面的代码中,您有实际的字符串'{$requestScope.someValue}'
@SubodhJoshi:不,它与这个问题的标题匹配,但与内容不匹配。不,我没有任何处理方法。@tuchargarg:那就是您的问题,它与var someValue='foo'完全相同代码>。您正在检查的值是实际字符串'{$requestScope.someValue}
。您是否有什么方法处理这些'{$requestScope.someValue}'
字符串文字?因为在上面的代码中,您有实际的字符串'{$requestScope.someValue}'
@SubodhJoshi:不,它与这个问题的标题匹配,但与内容不匹配。不,我没有任何处理方法。@tuchargarg:那就是您的问题,它与var someValue='foo'完全相同代码>。您正在检查的值是实际字符串{$requestScope.someValue}
。