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);
原文地址:https://www.cnblogs.com/wjhaaa/p/9042382.html
时间: 2024-10-10 13:44:23