form表单
<form action="" id="formdata" method="" onsubmit="return true"></form>
action写的是提交给对应服务器的路径
提交按钮在form上生效
method提交的方式 get或者post get不安全
οnsubmit=“return true” 提交成功
οnsubmit=“return flase” 提交失败
onfocus获焦事件 onblur失去焦点事件
表单验证
<label for="userid">账号:</label><input type="text" name="userid" class="txt">
lable标签写表单显示文字
lable里面for的内容时后面name名称,for可写可不写
正则表达式 验证数据
match() 验证成功返回值 验证失败返回null–字符串用法
var str=“123412”
str.match(正则表达式)
test() 验证成功返回true 验证失败flase–正则对象用法
var reg=new RegExp()
reg.test(str)
遍历
for(var i=0;i<a.length;i++){}
//可以遍历数组和字符串 字符串遍历需要转换数组 遍历json数据最层用for循环,内部用for in循环
for(var key in a){
console.log(a[index])
}
forEach遍历 value 数组中的每一个值;key数组中的索引;此遍历无返回值
var k=[1,2,3,4,5]
k.forEach(function(value,key){
console.log(value,key)
})
map方法遍历 有返回值 映射–原数组被影射为新的数组
k.map(function(value,key){
return value*value
})
reduce 累加器 映射
var data=k.reduce(function(v,v1){
return v+v1
})
conosle.log(data)
for循环 当length不存在时还会进入方法遍历,此时需要判断length是否存在,否则会报错
for( in) 循环 当内容不存在时不进行遍历