码迷,mamicode.com
首页 > Web开发 > 详细

如何循环html数据制作[{},{}]格式,向后台传递多个数据

时间:2018-05-15 19:46:38      阅读:226      评论:0      收藏:0      [点我收藏+]

标签:htm   push   fun   obj   循环   anti   UNC   div   his   

var allobject=[ ];
$(‘.P_center‘).each(function(){
                //获取对象所需要的值
                var courseId = $(this).data(‘id‘);
                var buyNum = $(this).data(‘quantity‘);
                var buyPrice = $(‘.P_su‘).text();

               //将获取好的值保存到对象中
                var object = {
                    "courseId":courseId,
                    "buyNum":buyNum,
                    "buyPrice":buyPrice
                }
               //将对象保存到数组中
                
                allobject.push(object );
            });
           //将数组转换为json类型的字符串
           var allobjectJSON = JSON.stringify(allobject);

如何循环html数据制作[{},{}]格式,向后台传递多个数据

标签:htm   push   fun   obj   循环   anti   UNC   div   his   

原文地址:https://www.cnblogs.com/wjhaaa/p/9042382.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!