gpt4 book ai didi

javascript - 在 javascript/jQuery 中有类似 isset of php 的东西吗?

转载 作者:IT老高 更新时间:2023-10-28 11:57:06 26 4
gpt4 key购买 nike

javascript/jQuery 中有什么东西可以检查变量是否设置/可用?在 php 中,我们使用 isset($variable) 来检查类似这样的内容。

谢谢。

最佳答案

试试这个表达式:

typeof(variable) != "undefined" && variable !== null

如果变量已定义且不为空,则为真,这与 PHP 的 isset 的工作方式等价。

你可以这样使用它:

if(typeof(variable) != "undefined" && variable !== null) {
bla();
}

关于javascript - 在 javascript/jQuery 中有类似 isset of php 的东西吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4231789/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com