如何确定页面中是否定义了JavaScript变量? [英] How can I determine if a JavaScript variable is defined in a page?

查看:172
本文介绍了如何确定页面中是否定义了JavaScript变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果在页面中定义了变量,我如何检查JavaScript?假设我想检查一个名为x的变量是否在页面中定义,如果我执行 if(x!= null),它会给我一个错误。

How can i check in JavaScript if a variable is defined in a page? Suppose I want to check if a variable named "x" is defined in a page, if I do if(x != null), it gives me an error.

推荐答案

我使用 if(typeof(x)!=undefined)

这篇关于如何确定页面中是否定义了JavaScript变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆