当前位置:网站首页>Judge whether the string is empty
Judge whether the string is empty
2022-06-28 19:21:00 【liaowenxiong】
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Check if the specified value is an empty string </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;
}
// Because the program will null Equate to undefined, So you can add the above function to if The conditional statement in the statement is simplified to the conditional statement shown in the following function
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>
Reference resources :https://blog.csdn.net/K346K346/article/details/113182838
边栏推荐
- 180.1. Log in continuously for n days (database)
- Month on month SQL implementation
- Rxjs map, mergeMap 和 switchMap 的区别和联系
- 行业分析| 快对讲,楼宇对讲
- C#连接数据库完成增删改查操作
- High performance and high availability computing architecture scheme commented by Weibo
- 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
- I. The HR system is put on the enterprise wechat ISV to enhance the in-depth application of enterprise wechat in service chain retail and other industries
- leetcode 1647. Minimum deletions to make character frequencies unique
- Cannot read property 'MTJ' of undefined
猜你喜欢

sql面试题:求连续最大登录天数

MDM data analysis function description

How does the computer check whether the driver is normal

Month on month SQL implementation

SQL interview question: find the maximum number of consecutive login days

基于趋势和季节性的时间序列预测

C#连接数据库完成增删改查操作

Opengauss kernel: analysis of SQL parsing process

机器学习笔记 temperature+Softmax

Question brushing analysis tool
随机推荐
Advanced - Introduction to business transaction design and development
Installation and configuration of CGAL in PCL environment 5.4.1
Grafana biaxial graph with your hands
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
泰山OFFICE技术讲座:WORD奇怪的字体高度
Tencent tangdaosheng: facing the new world of digital and real integration, developers are the most important "architects"
F(x)构建方程 ,梯度下降求偏导,损失函数确定偏导调整,激活函数处理非线性问题
多测师肖sirapp中riginal error: Could not extract PIDs from ps output. PIDS: [], Procs: [“bad pid
NanoPC-T4(RK3399) game1 oled(I2C)显示时间天气温度
pd.cut 区间参数设定之前后区别
Ffmpeg learning summary
Upward and downward transformation
Business layer modification - reverse modification based on the existing framework
matlab 二维或三维三角剖分
Technical methodology of new AI engine under the data infrastructure upgrade window
try except 添加辅助新列
About Critical Values
The white paper on the panorama of the digital economy and the digitalization of consumer finance were released
Servlet的使用手把手教学(一)
Chunfeng power and Huawei work together to build a smart Park benchmark, and the future factory innovation will reach a new level