在javascript / jQuery中有类似于php的东西吗? [英] is there something like isset of php in javascript/jQuery?
本文介绍了在javascript / jQuery中有类似于php的东西吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
javascript / jQuery中是否有东西可以检查变量是否设置/可用?在php中,我们使用 isset($ variable)
来检查这样的内容。
Is there something in javascript/jQuery to check whether variable is set/available or not? In php, we use isset($variable)
to check something like this.
谢谢。
推荐答案
试试这个表达式:
typeof(variable) != "undefined" && variable !== null
如果变量已定义且不为null,则为true相当于PHP的设置如何工作。
This will be true if the variable is defined and not null, which is the equivalent of how PHP's isset works.
您可以这样使用它:
if(typeof(variable) != "undefined" && variable !== null) {
bla();
}
这篇关于在javascript / jQuery中有类似于php的东西吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文