JS中怎样判断undefined(比较不错的方法)
时间:2024-04-19 09:54:20
最近做项目碰到的问题.拿出来跟大家分享一下吧.
用servlet赋值给html页面文本框值后,用alert来弹出这个值.结果显示"undefined".所以我就自然的用这个值和字符串"undefined"去比较,很不幸,比较的结果是false.
没办法,只能google一下,寻求大神了.
原来必须用typeof,写法就是:
if(typeof(value)=="undefined"){
alert("undefined");
}
这样就能顺利的弹出"undefined";
typeof 返回的是字符串,有六种可能:"number" "String" "boolean" "object" "function" "undefined"
标签:undefined
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
pyqt5让图片自适应QLabel大小上以及移除已显示的图片方法
2022-02-26 16:18:37
![](https://img.aspxhome.com/file/2023/5/95715_0s.jpg)
使用python模拟高斯分布例子
2021-04-27 05:22:22
![](https://img.aspxhome.com/file/2023/9/118359_0s.jpg)
基于python3监控服务器状态进行邮件报警
2022-05-05 05:25:39
![](https://img.aspxhome.com/file/2023/3/97343_0s.png)
keras输出预测值和真实值方式
2021-11-26 20:25:18
![](https://img.aspxhome.com/file/2023/9/83689_0s.jpg)
Python实现计算两个时间之间相差天数的方法
2022-11-09 06:04:59
PyQt5实现简易计算器
2022-12-14 02:12:38
![](https://img.aspxhome.com/file/2023/8/94148_0s.jpg)
python进度条显示之tqmd模块
2021-09-29 22:44:36
![](https://img.aspxhome.com/file/2023/9/85179_0s.png)
javascript结合ajax读取txt文件内容
2024-04-30 10:14:58
GoJs面板绘图模板go.Panel使用示例详解
2024-05-21 10:14:08
![](https://img.aspxhome.com/file/2023/0/125960_0s.jpg)
详解MySQL下InnoDB引擎中的Memcached插件
2024-01-24 22:02:35
Python中的map()函数和reduce()函数的用法
2021-10-19 01:04:34
![](https://img.aspxhome.com/file/2023/0/110360_0s.png)
golang 将[]byte转成16进制的实现
2024-02-17 00:35:03
Go使用协程批量获取数据加快接口返回速度
2024-05-21 10:23:38
Vue超详细讲解重试机制示例
2024-04-30 08:45:37
Python数据结构之栈、队列的实现代码分享
2023-12-07 12:39:08
![](https://img.aspxhome.com/file/2023/7/121617_0s.png)
python操作 hbase 数据的方法
2022-07-21 15:46:51
JDBC下Idea添加mysql-jar包的详细过程
2024-01-20 10:58:18
![](https://img.aspxhome.com/file/2023/7/78957_0s.jpg)
javascript获取来源的URL代码
2009-02-25 12:36:00
WPF滑块控件(Slider)的自定义样式
2022-01-19 20:05:02
![](https://img.aspxhome.com/file/2023/7/131847_0s.png)
Python读写JSON文件的操作详解
2021-03-22 11:46:35
![](https://img.aspxhome.com/file/2023/0/82670_0s.jpg)