首页 > Web开发 > 详细

Jquery的each遍历数据组成JSON

时间:2016-06-29 20:15:23      阅读:184      评论:0      收藏:0      [点我收藏+]

遍历每个标签的值

  html代码:

    <volist name="parArr" id="item" key="$key">
                     <tbody>
                             <tr>
                                   <td class="center number">{$key+1}</td>
                                    <td id=‘product_id‘ class="product_id">{$item.id}</td>
                                    <td>
                                          <a href="http://www.enkiorder.com/index.php/Home/detail/detail/id/{$item.id}" target="blank">{$item.name}</a>
                                     </td>

             <td>
                                           <input type="hidden" value={$item.cid} class="cid">
                                           <input type="text" style="width:50px" value="{$item.heat}">
                                      </td>
                                   </tr>
                         </tbody>
             </volist>

 

JS代码:

  <script type="text/javascript">
            // console.log(json);
            $(‘#add‘).click(function(){
                var json={};
                $(‘.cid‘).each(function(){
                    var cid=$(this).val();
                    var heat=$(this).next().val();
                    console.log(heat);
                    json[cid]=heat;
                })
                $.ajax({
                    type:"POST",
                    data:json,
                    url:"{:U(‘Categorys/update‘)}",
                    success:function(msg){
                        if(msg!=‘no‘){
                            alert(‘添加成功‘);
                            window.location.reload();
                        }
                    }
                })
            })
        </script>

Jquery的each遍历数据组成JSON

原文:http://www.cnblogs.com/sweet521/p/5627930.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!