zoukankan      html  css  js  c++  java
  • jquery笔记

    一、map与each的使用

     1 <html>
     2 <head>
     3 <meta charset="utf-8"> 
     4 <title>jquerydemo</title> 
     5 <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js">
     6 </script>
     7 <script>
     8 $(document).ready(function(){
     9   $("input").each(function(index, item){
    10       alert($(item).val());
    11   });
    12    $("input").map(function(){
    13       alert($(this).val());
    14   });
    15 });
    16 </script>
    17 </head>
    18 <body>
    19 <input type="text" value="1"/>
    20 <input type="text" value="2"/>
    21     <input type="text" value="3"/>
    22     <input type="text" value="4"/>
    23 </body>
    24 </html>

     二、ajax

        $(function () {
            $.ajax({
                type: "GET",
                url: "some",
                data: "name=John&location=Boston",
                success: function(msg){
                    alert( "Data Saved: " + msg.name );
                    alert( "Data Saved: " + msg.location );
                }
            });
        });
        $(function () {
            $.ajax({
                type: "POST",
                url: "some",
                data: "name=John&location=Boston",
                success: function(msg){
                    alert( "Data Saved: " + msg.name );
                    alert( "Data Saved: " + msg.location );
                }
            });
        });
     
    @RequestMapping("/some")
        @ResponseBody
        public Map<String, Object> getSome(String name, String location) throws IOException {
            System.out.println("GET");
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("name",name);
            map.put("location",location);
            return map;
        }
        @RequestMapping(value = "/some",method = RequestMethod.POST)
        @ResponseBody
        public Map<String, Object> postSome(String name, String location) throws IOException {
            System.out.println("POST");
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("name",name);
            map.put("location",location);
            return map;
        }

     三、JSON.parse()和JSON.stringify()区别

    JSON.parse()【从一个字符串中解析出json对象】
    
    例子:
    
    //定义一个字符串
    
    var data='{"name":"goatling"}'
    
    //解析对象​ 就是将json字符串转换为对象
    
    ​JSON.parse(data)
    
    结果是:
    
    ​name:"goatling"
    
    JSON.stringify()【从一个对象中解析出字符串】 说白了就是将json对象转换为字符串
    
    var data={name:'goatling'}
    
    JSON.stringify(data)
    
    结果是:
    
    '{"name":"goatling"}'
  • 相关阅读:
    JIRA4.1 主要功能
    linux之间的远程复制文件
    我在做测试 1
    JOGL简介与安装
    Eclipse RCP中的IAdaptable是什么?
    如何实现关系表的级联删除(ON DELETE CASCADE的用法)
    ubuntu 安装mysql+apache+php
    ubuntu10.10安装VMWare tools
    Struts2 Unable to load configuration. bean 错误解决
    MySQL Workbench “Error Code: 1175” 的解决方法
  • 原文地址:https://www.cnblogs.com/ya-qiang/p/9493598.html
Copyright © 2011-2022 走看看