jquery无法移出元素(form表单自动刷新)

今天遇到一个坑,想判断用户输入成功后使用jquery移出元素,但是失效,后来发现因为提交成功后     form表单自动刷新

1.html

 <!DOCTYPE html>  
    <html lang="en">  
    <head>  
        <meta charset="UTF-8">  
        <title>Login</title>  
         <link rel="stylesheet" type="text/css" href="Login.css"/>  
        <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
        <script src=".js"></script>   
    </head>  
    <body>  
        <div id="login">  
            <h1>first</h1> 
           <form method="post" onSubmit="return check(this);">  
                <input type="text" required="required" placeholder="考试密码" name="first"></input>
                <button class="but" type="submit">参与考试</button> </form>  
        </div>
    </body>  
    </html>  

first.js

function check(){
 if (form.first.value=="123456"){
  $("#login").fadeOut();//让login移除
  return true;
   }
   return false;
}

 
 

解决办法是去掉form标签,直接一个框子一个按钮,就可以了

2.html

 <!DOCTYPE html>  
    <html lang="en">  
    <head>  
        <meta charset="UTF-8">  
        <title>Login</title>  
         <link rel="stylesheet" type="text/css" href="Login.css"/>  
        <script src="http://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
        <script src="check2.js"></script>   
    </head>  
    <body>  
        <div id="login">  
            <h1>first</h1> 
            <input type="text" required="required" placeholder="考试密码" name="first" id="mytext"></input>
            <button class="but" type="submit" οnclick="check2()">参与考试</button> 
        </div>
    </body>  
    </html>  



check2.js

function check2(){
 if (document.getElementById("mytext").value=="123456"){
  $("#login").fadeOut();//让login移除
  }
  else{
  	document.getElementById("mytext").value="";
   }
 }

 
 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值