zoukankan      html  css  js  c++  java
  • form在ajax和JQajax中的使用

    ajax中

    (1)

    <div id="form">
        账号:<input type="text" name="" value=""><br>
        密码:<input type="text" name="" value=""><br>
        <button id="btn">登录</button>
       </div>
      <script type="text/javascript" src="ajax.js"></script>
      <script>
        var form=document.getElementById('form');
        var btn=document.getElementById('btn');
        var user=form.getElementsByTagName('input')[0];
        var pass=form.getElementsByTagName('input')[1];
        btn.onclick=function (){
          ajax('form.php?user='+user.value+'&pass='+pass.value,function (str){
            alert(str);
          });
        }
      </script>

    (2)

     

     <form method="get" action="form.php">
        账号:<input type="text" name="user" value=""><br>
        密码:<input type="text" name="pass" value=""><br>
            <input type="submit" name="" value="登录">
      </form>

    在JQajax中

      

    <form>
        用户名:<input type="text" value="" name="user">
        密码:<input type="password" value="" name="pass">
        <input id="btn" type="submit" value="提交">
      </form>
      <script src="jquery-1.8.3.min.js"></script>
      <script>
      $('#btn').click(function(){
        $.ajax({
          type:'get',
          url:'act.php',
          data:$('form').serialize(),
          dataType:'json',
          success:function(data){
            alert(data.msg);
          },
          error:function(e){
            alert(e);
          }
    
        });
      });
      </script>
  • 相关阅读:
    数组
    灰度转换
    类的定义和头文件
    读文件
    操纵元
    传递引用
    TensorFlow常用函数
    四、Item Pipeline
    三、Scrapy Shell
    二、Scrapy案例入门
  • 原文地址:https://www.cnblogs.com/SunShineM/p/6043837.html
Copyright © 2011-2022 走看看