当前位置:网站首页>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
边栏推荐
- 接口管理工具YApi怎么用?颜值高、易管理、超好用
- presto安装部署教程
- 【Harmony OS】【ARK UI】ETS 上下文基本操作
- Build your own web page on the Raspberry Pi (2)
- 业务表解析-余额系统
- Ali cloud object storage oss private barrels to generate links
- 信息编码、存储压缩与密码学
- Coordinate knowledge in digital twin campus scenarios
- 接口测试框架实战(三)| JSON 请求与响应断言
- Online password generator tool recommendation
猜你喜欢
Fluorescent marker peptides FITC/AMC/FAM/Rhodamine TAMRA/Cy3 / Cy5 / Cy7 - Peptide
荧光标记多肽FITC/AMC/FAM/Rhodamine/TAMRA/Cy3/Cy5/Cy7-Peptide
Coordinate knowledge in digital twin campus scenarios
【HMS core】【Ads Kit】华为广告——海外应用在国内测试正式广告无法展示
GIS数据漫谈(五)— 地理坐标系统
unity2D横板游戏教程6-敌人AI以及受击动画
在树莓派上搭建属于自己的网页(2)
Common lipophilic cell membrane dyes DiO, Dil, DiR, Did spectrograms and experimental procedures
Object类与常用API
Modified BiotinDIAZO-Biotin-PEG3-DBCO|diazo-biotin-tripolyethylene glycol-diphenylcyclooctyne
随机推荐
技术分享 | 接口自动化测试中如何对xml 格式做断言验证?
【HMS core】【Ads Kit】华为广告——海外应用在国内测试正式广告无法展示
MCM box model modeling method and source analysis of atmospheric O3
在线密码生成工具推荐
Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
【Biotin Azide|cas:908007-17-0】Price_Manufacturer
【开发者必看】【push kit】推送服务服务典型问题合集2
【Harmony OS】【FAQ】Hongmeng Questions Collection 1
Tag stack - stack monotonically preparatory knowledge - lt. 739. The daily temperature
Gradle的安装配置
C# async and multithreading
Practical application of WebSocket
js中的闭包
DFS's complement to pruning
presto安装部署教程
接口测试框架实战(四)| 搞定 Schema 断言
Where is the value of testers
修饰生物素DIAZO-生物素-PEG3-DBCO|重氮-生物素-三聚乙二醇-二苯基环辛炔
Interface Test Framework Practice | Process Encapsulation and Test Case Design Based on Encrypted Interface
shell script loop statement