zoukankan      html  css  js  c++  java
  • JQuery中根据表单元素动态拼接json 字符串

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript" src="/scripts/jquery/jquery-1.10.2.min.js"></script>
        <script type="text/javascript">
            $(function () {
    
                var jsonObj = {};
                jsonObj.a = "aaaa";
                var $input = $("input[id^='List_']");
                $input.each(function () {
    
                    var id = $(this).attr("id").replace("List_", "");
                    jsonObj[id] = "ccccc"; //$(this).val();
                })
    
                var str = JSON.stringify(jsonObj);
    
                alert(str);
    
    
            })
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
         
         <input id="List_nick" value="abc" />
              <input id="List_keyword" value="keyword" />
        </div>
        </form>
    </body>
    </html>

     alert 效果:{"a":"aaaa","nick":"ccccc","keyword":"ccccc"}

     后台可以使用NewTonJson.net 接收json字符串

  • 相关阅读:
    守护线程
    接口中的方法重写
    jvm内存结构
    浅拷贝,深拷贝
    队列
    12月4号荒度了一天
    同步条件
    条件变量
    信号量Semaphore
    sql练习
  • 原文地址:https://www.cnblogs.com/tiancai/p/5028392.html
Copyright © 2011-2022 走看看