当前位置:网站首页>判断字符串是否为空
判断字符串是否为空
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>
边栏推荐
猜你喜欢

Mybayis之核心主件分析

应用实践 | 10 亿数据秒级关联,货拉拉基于 Apache Doris 的 OLAP 体系演进(附 PPT 下载)

秋招经验分享 | 银行笔面试该怎么准备

深度学习需要多强的数学基础?

POI excel conversion tool

易观分析《2022年中国银行业隐私计算平台供应商实力矩阵分析》研究活动 正式启动

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

try except 添加辅助新列

牛津大學教授Michael Wooldridge:AI社區近40年如何看待神經網絡

Summary of the use of qobjectcleanuphandler in QT
随机推荐
Win11如何给系统盘瘦身?Win11系统盘瘦身方法
PCL 环境下安装配置CGAL 5.4.1
Brief introduction to mongodb working principle of mongodb series
use. NETCORE's own background job, which simply simulates producers and consumers' processing of request response data in and out of the queue
SQL calculates daily new users and retention rate indicators
易观分析《2022年中国银行业隐私计算平台供应商实力矩阵分析》研究活动 正式启动
在arm版本rk3399中搭建halo博客
sql面试题:求连续最大登录天数
Try except add auxiliary new column
数据基础设施升级窗口下,AI 新引擎的技术方法论
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奇怪的字体高度
Leetcode 周赛299
小白创业做电商,选对商城系统很重要!
Win11底部状态栏如何换成黑色?Win11底部状态栏换黑色的方法
async-validator.js数据校验器
Can py SQL get the table structure?
毕业设计-基于Unity的餐厅经营游戏的设计与开发(附源码、开题报告、论文、答辩PPT、演示视频,带数据库)
Live app system source code, automatically playing when encountering video dynamically
math_ Proving common equivalent infinitesimal & Case & substitution