当前位置:网站首页>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
边栏推荐
- Shell conditional statement judgment
- 接口测试如何准备测试数据
- Alienware上线首个数字时装AR试穿体验
- Interface testing framework combat (3) | JSON request and response assertion
- idea uses @Autowired annotation to explain the reasons and solutions
- 在树莓派上搭建属于自己的网页(2)
- Common fluorescent dyes to modify a variety of groups and its excitation and emission wavelength data in the data
- FileZilla 搭建ftp服务器
- BIOTIN ALKYNE CAS:773888-45-2价格,供应商
- Fluorescent marker peptides FITC/AMC/FAM/Rhodamine TAMRA/Cy3 / Cy5 / Cy7 - Peptide
猜你喜欢

在树莓派上搭建属于自己的网页(1)

Kotlin-Flow常用封装类:StateFlow的使用

Unity2D horizontal board game tutorial 6 - enemy AI and attack animation

Kotlin-Flow common encapsulation class: the use of StateFlow

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

Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne

【HMS core】【Ads Kit】Huawei Advertising——Overseas applications are tested in China. Official advertisements cannot be displayed

Bubble sort in c language structure

Coordinate knowledge in digital twin campus scenarios

typescript40-class类的保护修饰符
随机推荐
【Harmony OS】【ArkUI】ets开发 图形与动画绘制
C#异步和多线程
用户密码加密工具
【精讲】利用原生js实现todolist
idea uses @Autowired annotation to explain the reasons and solutions
Shell conditional statement judgment
Unity2D horizontal board game tutorial 6 - enemy AI and attack animation
JDBC与连接池
Interface testing framework of actual combat (2) | interface request assertion
Create a tree structure
PotPlayer实现上班摸鱼电视自由
【 Harmony OS 】 【 ano UI 】 lightweight data storage
探索性测试的概念及方法
2. 两数相加
Interface test framework combat (1) | Requests and interface request construction
MCM box model modeling method and source analysis of atmospheric O3
1095 解码PAT准考证 (25 分)(C语言)
接口和抽象
Power button 561. An array of split
1079 延迟的回文数 (20 分)