码迷,mamicode.com
首页 > Web开发 > 详细

自动化开发学习18-Web前端

时间:2018-12-01 22:00:51      阅读:246      评论:0      收藏:0      [点我收藏+]

标签:自定义事件   code   默认   点击   个数   多行   function   python   web前端   

 

Python自动化开发学习18-Web前端

js正则表达式

  test  --判断字符串是否符合规定的正则,返回布尔值(true 或 false)

  exec --获取匹配的数据,匹配不到则返回 null。返回一个数组,可以对返回的结果再次匹配。

首先要创建正则表达式对象

python中的写法是a = “字符串”

js中的写法是用/ /:rel = /\d+/

rel = /\d+/  //匹配数字
/\d+/
rel.test("dfsdfsfs454fgfgdfgfgf")
true
rel.test("dfsdfsfsfgfgdfgfgf")
false
rel.exec("dfsdfsfs454fgfgdfgfgf")
["454", index: 8, input: "dfsdfsfs454fgfgdfgfgf", groups: undefined]

匹配纯数字

rel = /^\d+$/;
/^\d+$/
rel.test("12345")
true
rel.test("123df45")
false

/\b  \b /:表示匹配的是单词,中间有空格的字符串

(\w)加括号表示分组匹配,会先整体匹配,再在每个分组中匹配,这次只匹配分组的内容

/……/g:全局匹配

/……/i:不区分大小写

/……/m:匹配多行,默认是多行匹配,但是想匹配有^,$的,就需要在后面加上m了

reg = /\bjava\w*\b/;
/\bjava\w*\b/
text =  "JavaScript is more fun than Java or JavaBeans!";
"JavaScript is more fun than Java or JavaBeans!"
reg.exec(text)
null
reg = /\bJava\w*\b/;
/\bJava\w*\b/
reg.exec(text)
["JavaScript", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg = /Java(\w*)/;
/Java(\w*)/
reg.exec(text)
(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg = /\bJava(\w*)\b/;
/\bJava(\w*)\b/
reg.exec(text)
(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg = /Java(\w*)/g;
/Java(\w*)/g
reg.exec(text)
(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg = /Java\w*/g;
/Java\w*/g
reg.exec(text)
["JavaScript", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
text =  "JavaScript is more fun than Java or JavaBeans!";
"JavaScript is more fun than Java or JavaBeans!"
reg = /Java\w*/g;
/Java\w*/g
reg.exec(text)
["JavaScript", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg = /\bJava(\w*)\b/g;
/\bJava(\w*)\b/g
reg.exec(text)
(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg.exec(text)
(2) ["Java", "", index: 28, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg.exec(text)
(2) ["JavaBeans", "Beans", index: 36, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg.exec(text)
null
reg.exec(text)
(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg = /\bJava(\w*)\b/;
/\bJava(\w*)\b/
reg.exec(text)
(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg.exec(text)
(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than Java or JavaBeans!", groups: undefined]
reg = /^Java(\w*)/gm;
/^Java(\w*)/gm
reg.exec(text)
(2) ["JavaScript", "Script", index: 0, input: "JavaScript is more fun than ?Java or JavaBeans!", groups: undefined]
reg.exec(text)
(2) ["Java", "", index: 29, input: "JavaScript is more fun than ?Java or JavaBeans!", groups: undefined]
reg.exec(text)
null

阻止事件发生

事件执行循序

自定义事件先执行:

大部分的都是自定义事件先执行,如a标签,subit

a:绑定事件后,会先执行自定义的事件,在进行跳转

默认事件先执行:

这种情况比较少,比如复选框(checkbox)

<body>
<a id="l1" href="http://www.baidu.com">先弹出警告,再跳转</a>
<input id="i1" type="checkbox">
<script src="jquery-3.2.1.min.js"></script>
<script>
    document.getElementById(‘l1‘).onclick = function () {
        alert("我是先执行自定义事件")
    };
    document.getElementById(‘i1‘).onclick = function () {
        //这里有两个事件,点击和不点击,不点击是默认事件,因为此时checkbox没有选择算是事件
        console.log($("#i1").prop("checked"));
    };
</script>
</body>

表单验证

 

自动化开发学习18-Web前端

标签:自定义事件   code   默认   点击   个数   多行   function   python   web前端   

原文地址:https://www.cnblogs.com/Aline2/p/10050655.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!