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>
  • 相关阅读:
    js、css等文件引入空白问题
    Vue 组件 data为什么是函数
    安装Node,创建vue项目,运行及打包
    JQuery移除事件
    百度地图定位
    移动端导航过多,点击导航左右滚动回弹
    移动端开发模板
    移动端左右滑动导航
    使用‘圣杯布局’、‘双飞翼布局’来解释自适应的三栏水平布局
    css实现三角箭头
  • 原文地址:https://www.cnblogs.com/SunShineM/p/6043837.html
Copyright © 2011-2022 走看看