当前位置:网站首页>JS学习笔记(三)
JS学习笔记(三)
2022-08-03 05:09:00 【一个从机械跳计算机的小菜鸡】
innerHTML和innnerText操作div和span
innerHTML是将后面的字符串当作html语言脚本来处理
innerText是将后面的字符串当作Text文本来处理
<head>
<meta charset="utf-8">
<title>innerHTML和innerText的作用的区分</title>
<style>
#div1{
background-color: aqua;
width: 300px;
height: 300px;
border:1px black solid;
position: absolute;
top:100px;
left:100px;
}
</style>
</head>
<body>
<script type="text/javascript">
window.onload=function(){
document.getElementById("mybtn").onclick=function(){
document.getElementById("div1").innerHTML="<a href='http://www.baidu.com'>你好</a><br>"
document.getElementById("div1").innerText="<a href='http://www.baidu.com'>你好</a><br>"
}
}
</script>
<div id="div1"></div>
<input type="button" id="mybtn" value="mybtn"/>
</body>

正则表达式:
什么是正则表达式有什么用? 字符串格式匹配 是一门独立的研究
第一:常见的符号
第二:简单的正则表达要会写
第三:要会创建正则表达式对象,正则表达式的方法有哪些

(101条消息) 正则表达式全解析+常用示例_墨遥的博客-CSDN博客_正则表达式例子详解


写两个程序:一个是验证邮箱的地址是否合法的,另一个是去除空格的
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>验证邮箱地址是否准确</title>
</head>
<body>
<script type="text/javascript">
window.onload=function(){
document.getElementById("mybtn").onclick=function(){
var emailRegExp = /^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/
if(!(emailRegExp.test(document.getElementById("text01").value))){
document.getElementById("emailerror").innerText="邮箱输入格式不正确"
}
document.getElementById("text01").onfocus=function(){
document.getElementById("emailerror").innerText=""
}
}
}
</script>
<input type="text" id="text01"/>
<input type="button" id="mybtn" value="提交"/>
<span id="emailerror" style="color: red;"></span>
</body>
</html>
【chrome】浏览器debug js 技巧分享 | 简单入门_哔哩哔哩_bilibili


下面的这个用到了全局搜索:

详解和示例:
(1). 匹配任何任意字符 例如 . 可以匹配 1,n,*,+,- ,等
(2)\d\w\s 匹配第一个字符为数字,第二个字符为字母或数字、或下划线或汉字,第三字符为空格的字符串 例如:11 ,2a , 1_
(3)^\d\d\d$ 匹配三个全部都为数字的字符串 例如: 123,456,789
还可以用于验证输入的字符串是否符合qq(身份证号)的验证 :
例如:^\d{8}$ 匹配8位数字的qq号,^\d{15}&匹配15位均为数字的身份证号
(4)\bOlive\b 匹配单词Olive 例如: I Love Oliver and Olive .这个时候返回的是Olive 而不是Oliver,因为\b....\b返回的匹配的单词
详解和示例:
(1)\d* 匹配重复0次或多次数字 例如:可能为空 或 任意数字 (2,3。。。。)
(2)\d+ 匹配重复1次或多次数字 例如:可能为1个或多个数字 1,23,234,2345,........
(3)\d? 匹配重复次个或者一次数字 例如:可能为空或者任意的一个数字(1,2,。。。)
(4)\d{8}匹配重复8次数字 例如:123456768
(5)\d{4,}匹配重复至少4次数字 例如:1234,12345,124244,。。。。。
(6)^\d{8,11}$ 匹配重复8-11次数字 例如:12345678,123456789,1234567890,12345678901
边栏推荐
- BIOTIN ALKYNE CAS: 773888-45-2 Price, Supplier
- Bubble sort in c language structure
- DFS对剪枝的补充
- Kotlin-Flow common encapsulation class: the use of StateFlow
- 用户密码加密工具
- Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
- Windows 安装PostgreSQL
- IO process thread -> thread -> day5
- Power button 561. An array of split
- 【生物素叠氮化物|cas:908007-17-0】价格_厂家
猜你喜欢

Shell conditional statement judgment

接口和抽象

js实现一个 bind 函数

idea使用@Autowired注解爆红原因及解决方法

Peptides mediated PEG DSPE of phospholipids, targeted functional materials - PEG - RGD/TAT/NGR/APRPG

MOSN 反向通道详解

Online password generator tool recommendation

typescript46-函数之间的类型兼容性

Two ways to simulate multi-user login in Jmeter

Windows 安装PostgreSQL
随机推荐
WinForm的控件二次开发
Concepts and Methods of Exploratory Testing
接口测试框架实战 | 流程封装与基于加密接口的测试用例设计
数字孪生园区场景中的坐标知识
shell脚本循环语句
Talking about GIS Data (6) - Projected Coordinate System
[Harmony OS] [ARK UI] ETS context basic operations
js的垃圾回收机制
【HMS core】【Ads Kit】华为广告——海外应用在国内测试正式广告无法展示
1059 C语言竞赛 (20 分)(C语言)
荧光标记多肽FITC/AMC/FAM/Rhodamine/TAMRA/Cy3/Cy5/Cy7-Peptide
typescript49-交叉类型
typescript42-readonly修饰符
2022/08/02 学习笔记 (day22) 多线程
在树莓派上搭建属于自己的网页(1)
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
Windows 安装PostgreSQL
presto安装部署教程
Technology Sharing | How to do assertion verification for xml format in interface automation testing?
User password encryption tool