当前位置:网站首页>判断字符串是否为空
判断字符串是否为空
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>
边栏推荐
- Month on month SQL implementation
- 原生实现.NET5.0+ 自定义日志
- Hands on Teaching of servlet use (1)
- 180.1. Log in continuously for n days (database)
- rancher增加/删除node节点
- sql计算每日新增用户、及留存率指标
- Mybayis之核心主件分析
- There are thousands of roads. Why did this innovative storage company choose this one?
- Paper 3 vscode & texlive & sumatrapdf create a perfect tool for writing papers
- [C #] explain the difference between value type and reference type
猜你喜欢

使用点云构建不规则三角网TIN

道路千万条,为什么这家创新存储公司会选这条?

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

电脑如何检查驱动程序是否正常

团体程序设计天梯赛练习题-持续更新中

Sound network releases lingfalcon Internet of things cloud platform, which can build sample scenarios in one hour

Upward and downward transformation

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

OpenHarmony—内核对象事件之源码详解

数据基础设施升级窗口下,AI 新引擎的技术方法论
随机推荐
深入解析kubernetes中的选举机制
MDM数据分析功能说明
Memory leak
Win11底部状态栏如何换成黑色?Win11底部状态栏换黑色的方法
sql面试题:求连续最大登录天数
机器学习笔记 temperature+Softmax
怎样去除DataFrame字段列名
math_证明常用等价无穷小&案例&代换
智能计算系统3 Plugin 集成开发的demo
How to change the status bar at the bottom of win11 to black? How to change the status bar at the bottom of win11 to black
MongoDB系列之MongoDB工作原理简单介绍
易观分析《2022年中国银行业隐私计算平台供应商实力矩阵分析》研究活动 正式启动
Michael Wooldridge, professeur à l'Université d'Oxford: comment la communauté de l'IA voit les réseaux neuronaux depuis près de 40 ans
Cannot read property 'MTJ' of undefined
SQL interview question: find the maximum number of consecutive login days
Web3 that unleashes the value of the Internet
How does the computer check whether the driver is normal
Anonymous function this pointing and variable promotion
使用Karmada实现Helm应用的跨集群部署
Mybayis之核心主件分析