当前位置:网站首页>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
边栏推荐
- [Developers must see] [push kit] Collection of typical problems of push service service 2
- 在线密码生成工具推荐
- 1095 解码PAT准考证 (25 分)(C语言)
- 接口测试框架实战(一) | Requests 与接口请求构造
- User password encryption tool
- 【Harmony OS】【ARK UI】ets使用startAbility或startAbilityForResult方式调起Ability
- 13.
lt.647. Palindromic substring + lt.516. Longest palindrome subsequence - Concepts and Methods of Exploratory Testing
- 探索性测试的概念及方法
- Exception (abnormal) and Error (error) difference analysis
猜你喜欢
随机推荐
Tributyl-mercaptophosphane "tBuBrettPhos Pd(allyl)" OTf), 1798782-17-8
Super handy drawing tool is recommended
typescript42-readonly修饰符
业务表解析-余额系统
High availability, two locations and three centers
Windows 安装PostgreSQL
C# async and multithreading
【Harmony OS】【ARK UI】ets use startAbility or startAbilityForResult to invoke Ability
typescript43-类型兼容性说明
接口测试实战| GET/POST 请求区别详解
The problem that the rosbag tool plotjuggler cannot open rosbag
【Harmony OS】【ArkUI】ets开发 图形与动画绘制
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
[Harmony OS] [ARK UI] ETS context basic operations
VR全景展打造专属元宇宙观展空间
typescript44-对象之间的类兼容器
【Harmony OS】【FAQ】鸿蒙问题合集1
3. 无重复字符的最长子串
1058 选择题 (20 分)(C语言)
JDBC与连接池







