我怎么让刷新页面的时候先不去验证对不对呢?

我怎么让刷新页面的时候先不去验证对不对呢?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
 
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>html5表单美化综合案例演示美化案例</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
</head>
<style>
.onelist{margin:10px 0 5px 12px;}
.onelist label{width:80px;display:inline-block}
.onelist input,.onelist select{height:25px;line-height:25px;width:220px;border-radius:3px;border:1px solid #e2e2e2;}
.onelist input[type="submit"]{width:150px;height:30px;line-height:30px;}
 
.myform select:required,
.myform input:required,
.myform textarea:required {
    background: #fff url(img/star.jpg) no-repeat 99% center;
}
 
.myform select:required:valid,
.myform input:required:valid,
.myform textarea:required:valid {
    background: #fff url(img/right.png) no-repeat 99% center;
    box-shadow: 0 0 5px #5cd053;
    border-color: #28921f;
}
 
.myform select:focus:invalid,
.myform input:focus:invalid,
.myform textarea:focus:invalid {
    background: #fff url(img/error.png) no-repeat 99% center;
    box-shadow: 0 0 5px red;
    border-color: red;
    outline: red solid 1px;
}
 
</style>
 
<body>
 
<form class="myform" onsubmit="return checkForm();" method="post">
    <div class="onelist">
    <label for="UserName">手机号</label>
        <input name="UserName" id="UserName" type="text" placeholder="请输入手机号码"  pattern="^1[0-9]{10}$" required oninvalid="this.setCustomValidity('请输入正确的号码');" oninput="setCustomValidity('')">
    </div>
    <div class="onelist">
    <label for="Password">密码</label
        <input name="Password" id="Password" type="password" placeholder="6~20位" class="" pattern="^[a-zA-Z0-9]\w{5,19}$" required oninvalid="this.setCustomValidity('6~20字母数字或下划线');" oninput="setCustomValidity('')" onchange="checkPassword()">
    </div>
    <div class="onelist">
    <label for="Repassword">确认密码</label
        <input name="Repassword" id="Repassword" type="password" placeholder="确认密码" class="" required onchange="checkPassword()">
    </div>
    <div class="onelist">
    <label for="Repassword">了解方式</label>                         
        <select name="konw" required>
        <option value="">==请选择==</option>
        <option value="1">搜索引擎</option>
            <option value="2">朋友圈</option>
            <option value="3">朋友推广</option>
            <option value="4">广告投放</option>
      </select>
    </div>
 
    <div class="onelist"><input type="submit"  value="提交"></div>
 
</form>
 
 
    <script type="text/javascript">
        function checkPassword() {
            var pass1 = document.getElementById("Password");
            var pass2 = document.getElementById("Repassword");
      
            if (pass1.value != pass2.value)
                pass2.setCustomValidity("两次输入的密码不匹配");
            else
                pass2.setCustomValidity("");
        }
 
        // 验证表单
        function checkForm() {
            // ajax检测账号是否已存在
             
            // return false;
        }
    </script>
</body>
 
</html>


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
卡布琦诺 2018-04-16 13:39:31

亲是使用什么浏览器进行测试的呢?我这边测试了是需要点击按钮才会有验证的呢~

  • 提问者 慕斯卡5217687 #1
    今天又好了。不知道为啥,那天当时写完代码去浏览器运行就自己提示了不能为空啊什么的
    2018-04-17 11:21:02
正在想名字呢 2018-04-16 10:59:26

测试你的代码,刷新页面并没有验证表单啊~

  • 提问者 慕斯卡5217687 #1
    不是啊,我的一刷新或者直接打开页面就验证啊,就是还没有点击提交按钮,那些不能为空的信息就自己把不能为空的样式显示出来了
    2018-04-16 12:00:39
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
响应式开发与常用框架 2018
  • 参与学习           人
  • 提交作业       2198    份
  • 解答问题       5012    个

如果你有web端基础,既想进阶,又想进军移动端开发,那就来吧,我们专题为你带来的课程有HTML5、CSS3、移动基础、响应式、bootstrap、less等,让你在前端道路上畅通无阻!

了解课程
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师
插入代码