当前位置:网站首页>判断字符串是否为空
判断字符串是否为空
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>
边栏推荐
- Show the actual work case of creating intermediate data table with SQL
- 智能计算系统1 环境搭建
- Taishan Office Technology Lecture: word strange font height
- 怎样去除DataFrame字段列名
- Ffmpeg learning summary
- Native implementation Net5.0+ custom log
- Modular operation
- 3D可旋转粒子矩阵
- Grafana biaxial graph with your hands
- About Statistical Distributions
猜你喜欢

Advanced - Introduction to business transaction design and development

Paper 3 vscode & texlive & sumatrapdf create a perfect tool for writing papers

视频压缩处理之ffmpeg用法

There are thousands of roads. Why did this innovative storage company choose this one?

Opengauss kernel: analysis of SQL parsing process

智能计算系统1 环境搭建

Month on month SQL implementation

Modular operation

大火的虚拟人在哪些产业开始发力?

grafana绘制走势图
随机推荐
Differences and relations among rxjs map, mergemap and switchmap
math_证明常用等价无穷小&案例&代换
从设计交付到开发,轻松畅快高效率!
CVPR2022 | 浙大、蚂蚁集团提出基于标签关系树的层级残差多粒度分类网络,建模多粒度标签间的层级知识
C# 41. int与string互转
泰山OFFICE技术讲座:WORD奇怪的字体高度
Installing the nodejs environment
Technical methodology of new AI engine under the data infrastructure upgrade window
Show the actual work case of creating intermediate data table with SQL
Understanding of closures
数据基础设施升级窗口下,AI 新引擎的技术方法论
Get the timestamp of 0:00 and 23:59 of the current date
A few lines of code can realize complex excel import and export. This tool class is really powerful!
声网发布灵隼物联网云平台 可一小时构建示例场景
use. NETCORE's own background job, which simply simulates producers and consumers' processing of request response data in and out of the queue
释放互联网价值的 Web3
智能计算系统2 bangc算子开发的demo (CPU和MLU270的异构编程流程)
Memory leak
F(x)构建方程 ,梯度下降求偏导,损失函数确定偏导调整,激活函数处理非线性问题
Brief introduction to mongodb working principle of mongodb series