zoukankan      html  css  js  c++  java
  • jquery中的 ajax 以及map遍历

    1.语法

     $.ajax{

      type:'get',//类型 有get post

      url:'',//路径

      data:{name:$('#ma').val(),nameq:$('#maq').val()},

      dataType="json",

      success:function(data){alert("成功了")}

     }

    2.获取data数据的方法

    如果这样写的话会写吐血的name:$('#ma').val(),nameq:$('#maq').val()

    可以用map方法

    var map=$(':checkbox').map(function() {
      return ($(this).attr("id")+'='+$(this).val());
    }).get().join('&');
    alert(map)

    <form method="post" action="">
      <fieldset>
        <div>
          <label for="two">2</label>
          <input type="checkbox" value="2" id="two" name="number[]">
        </div>
        <div>
          <label for="four">4</label>
          <input type="checkbox" value="4" id="four" name="number[]">
        </div>
        <div>
          <label for="six">6</label>
          <input type="checkbox" value="6" id="six" name="number[]">
        </div>
        <div>
          <label for="eight">8</label>
          <input type="checkbox" value="8" id="eight" name="number[]">
        </div>
      </fieldset>
    </form>
    
    </body>
    <script>
      var map=$(':checkbox').map(function() {
        return ($(this).attr("id")+'='+$(this).val());
      }).get().join('&');
      alert(map)
    </script>
  • 相关阅读:
    vscode调试pomelo和pomelo使用vscode调试
    linux修改单个进程的系统时间
    python之路目录
    python之前端
    python之ORM操作
    python之redis和memcache操作
    python之消息队列
    python之协程与IO操作
    python之进程与线程
    python之网络编程
  • 原文地址:https://www.cnblogs.com/songrimin/p/4451402.html
Copyright © 2011-2022 走看看