使用jQuery将数据从一页传递到另一页 [英] Passing Data from one page to another using jQuery

查看:114
本文介绍了使用jQuery将数据从一页传递到另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据结帐页面上的数据来制定url字符串.我需要从购物车中的物品中提取所有产品代码,数量和价格,并创建一个用于会员跟踪的字符串.该字符串需要在结帐页面上呈现.这是html结构.

I need to formulate a url string from data on a checkout page. I need to take all the product codes, quantities and prices from items in a cart and create a string for use in affiliate tracking. This string needs to be rendered on the checkout page. Here's the html structure.

<span class="productCodeID">
<div class="productitemcell">123456</div>
<div class="productitemcell">789123</div>
</span>
<span class="productQuantityID">
<div class="productitemcell"><input type="text" value="3"></div>
<div class="productitemcell"><input type="text" value="1" ></div>
</span>
<span class="productPriceID">
<div class="productitemcell">$15.00</div>
<div class="productitemcell">$19.50</div>
</span>

我需要构建的是这样:

&skulist=123456,789123&pricelist=15.00,19.50&quantitylist=3,1

此字符串需要传递到确认页面.只是寻找有关如何完成此操作的指导.预先感谢!

This string needs to be passed to the confirmation page. Just looking for a little guidance on how to accomplish this. Thanks in advance!

推荐答案

function buildList(items, name) {
  var values = [];
  items.each(function() {
    values.push(this.value || $(this).text());
  });
  return name + '=' + values.join(',');
}

var result = [
  buildList($('.productCodeID > .productitemcell'), 'skulist'),
  buildList($('.productQuantityID > .productitemcell > input'), 'quantitylist'),
  buildList($('.productPriceID > .productitemcell'), 'pricelist')
];

var string = result.join('&');

在JSBin上的工作示例

这篇关于使用jQuery将数据从一页传递到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆