js check variable empty
javascript – How to check if a value is not null and not empty string in JS – Stack Overflow
javascript – How to check if a value is not null and not empty string in JS – Stack Overflow
Checking for undefined, null, and empty variables in JavaScript | David Calhoun
【总结】
最后是
<code>if( jsVariable ) { } </code>
可以实现相反的:
判断变量是否不为空,不是:
null
undefined
NaN
empty string (“”)
0
false
所以想要判断不为空,则可以:
<code>if ( jsVariable ) { } else { // do what you want to do } </code>
比如:
此处当http的response是空时,提示用户名或密码出错:
转载请注明:在路上 » 【已解决】js中判断变量是否为空