当前位置:网站首页>判断字符串是否为空
判断字符串是否为空
2022-06-28 19:07:00 【liaowenxiong】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>检查指定的值是不是空字符串</title>
<script>
function test_1() {
// var name = document.getElementById("name").value;
// alert(name);
var name = null;
// var flag = isEmptyStr(name);
var flag = isEmptyStrV2(name);
alert(flag);
}
function test_2() {
var flag_1 = null == undefined; // true
var flag_2 = null === undefined; // false
alert(flag_1);
alert(flag_2);
}
function test_3(s) {
alert(s);
var flag = isEmptyStr(s);
alert(flag);
}
function isEmptyStr(s) {
if (s == undefined || s == null || s.trim() === '') {
return true
}
return false
}
function isEmptyStrV2(s) {
if (typeof s == 'string' && s.trim().length == 0) {
return true;
} else if (s == null) {
return true;
}
return false;
}
// 因为程序将null等同于undefined,所以可以将上述函数中if语句中的条件语句简化成下面函数所示的条件语句
function isEmptyStr(s) {
if (s == undefined || s.trim() === '') {
return true
}
return false
}
</script>
</head>
<body>
<label for="name">name:</label>
<input id="name" type="text" name="name"/>
<button type="button" onclick="var name = document.getElementById('name').value;test_3(name);">Click Me!</button>
<!--<button type="button" onclick="test_1();">Click Me!</button>-->
<!--<button type="button" onclick="test_2();">Click Me!</button>-->
</body>
</html>
边栏推荐
- Analysis of the core components of mybayis
- 找出连续7天登陆,连续30天登陆的用户
- Jenkins Pipeline 对Job参数的处理
- leetcode 1423. Maximum points you can obtain from cards
- Markdown绘图mermaid实用教程
- Summary of the use of qobjectcleanuphandler in QT
- 春风动力携手华为打造智慧园区标杆,未来工厂创新迈上新台阶
- [C #] explain the difference between value type and reference type
- First day of new work
- 从设计交付到开发,轻松畅快高效率!
猜你喜欢

Cvpr2022 | Zhejiang University and ant group put forward a hierarchical residual multi granularity classification network based on label relation tree to model hierarchical knowledge among multi granu

NanoPC-T4(RK3399) game1 oled(I2C)显示时间天气温度

Analysis of the core components of mybayis

shell读取Json文件的值

3D rotatable particle matrix

i人事HR系统上架企业微信ISV,增强企微在服务连锁零售等行业深度应用

Mybayis之核心主件分析

春风动力携手华为打造智慧园区标杆,未来工厂创新迈上新台阶

《数字经济全景白皮书》消费金融数字化篇 重磅发布

3D可旋转粒子矩阵
随机推荐
matlab 二维或三维三角剖分
内核错误怎么解决?Win11系统内核错误解决方法
Baidu time factor addition
C# 41. int与string互转
Web3 that unleashes the value of the Internet
福建的朋友们,你们的养老保险上云啦!
Technical methodology of new AI engine under the data infrastructure upgrade window
[unity3d] camera follow
PY SQL可以获取到表结构吗?
1 goal, 3 fields, 6 factors and 9 links of digital transformation
Are there any regular and safe foreign exchange dealers in China?
async-validator. JS data verifier
Cross cluster deployment of helm applications using karmada
Render function parsing
A few lines of code can realize complex excel import and export. This tool class is really powerful!
About Statistical Distributions
new String(“hello“)之后,到底创建了几个对象?
直播app系统源码,动态遇到视频时开始自动播放
《数字经济全景白皮书》消费金融数字化篇 重磅发布
应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)