当前位置:网站首页>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
边栏推荐
- DFS's complement to pruning
- UV 裂解的生物素-PEG2-叠氮|CAS:1192802-98-4生物素接头
- Tag stack - stack monotonically preparatory knowledge - lt. 739. The daily temperature
- MCM box model modeling method and source analysis of atmospheric O3
- 高可用 两地三中心
- js实现一个 bind 函数
- typescript41-class类的私有修饰符
- 常见荧光染料修饰多种基团及其激发和发射波长数据一览数据
- shell script loop statement
- 【Harmony OS】【ARK UI】Date 基本操作
猜你喜欢

13.
lt.647. Palindromic substring + lt.516. Longest palindrome subsequence 
接口管理工具YApi怎么用?颜值高、易管理、超好用

Build your own web page on raspberry pie (1)

DFS's complement to pruning

idea uses @Autowired annotation to explain the reasons and solutions

1. 两数之和

Kotlin-Flow common encapsulation class: the use of StateFlow

高可用 两地三中心

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

在树莓派上搭建属于自己的网页(1)
随机推荐
Bubble sort in c language structure
Get the Ip tool class
Tag stack - stack monotonically preparatory knowledge - lt. 739. The daily temperature
Apache DolphinScheduler版本2.0.5分布式集群的安装
接口管理工具YApi怎么用?颜值高、易管理、超好用
设计模式——组合模式、享元模式(Integer缓存)(结构型模式)
阿里云对象存储oss私有桶生成链接
【Harmony OS】【ARK UI】ETS 上下文基本操作
Harmony OS ets ArkUI 】 【 】 the development basic page layout and data connection
【Harmony OS】【ARK UI】ets使用startAbility或startAbilityForResult方式调起Ability
接口测试框架实战(一) | Requests 与接口请求构造
Shell conditional statement judgment
【Harmony OS】【ArkUI】ets开发 图形与动画绘制
js implements a bind function
CAD有生僻字如何打出来、如何提交软件相关问题或建议?
UV 裂解的生物素-PEG2-叠氮|CAS:1192802-98-4生物素接头
[Fine talk] Using native js to implement todolist
VR全景展打造专属元宇宙观展空间
User password verification
Fluorescent marker peptides FITC/AMC/FAM/Rhodamine TAMRA/Cy3 / Cy5 / Cy7 - Peptide