XML/XSL 和 Javascript 购物车
XML/XSL and Javascript Shopping Cart
我的大学作业是使用 HTML、XSL、XML 和 Javascript 创建购物车。我决定使用 XML/XSL 和 Javascript。
我已经设法让 table 与我的基本结构的 javascript 按钮一起显示。我的问题是,如何使用 javascript 函数中的 XML 数据。
我的代码可以在这里找到:
http://xsltransform.net/3Nqn5Yo/11
javascript 代码目前只是占位符,因为它不起作用。我想解决的是如何在 Javascript 函数 "function AddtoCart(name,description,price)".
中使用我的 XML 数据
我刚刚在此处调整了您的代码:http://xsltransform.net/3Nqn5Yo/12
如果你想在每个 AddToCart()
调用中直接拥有 XML 数据,调整如下:更改 previous
<button type="button" onclick="AddtoCart('$Product','$Description','$price')">
进入
<button type="button" onclick="AddtoCart('{Product}','{Description}','{price}')">
Add one to cart
</button>
使用 {}
在转换时计算变量。
示例结果:
<button type="button" onclick="AddtoCart('Belts (F)','Woven Finish Fashion Belt','£21.99')">
Add one to cart
</button>
其他详细信息 - 正如我注意到的那样,由于此表达式,转换后的脚本将无法运行
while (orderedProductsTblBody.rows.length & gt;
这可以通过将脚本部分编写为 <xsl:text>
并使用 disable-output-escaping="yes"
来处理,如下所示:
<xsl:text disable-output-escaping="yes">
<script>
... // rest of code stays the same as before
<script>
</xsl:text>
结果是
<script>
...
while(orderedProductsTblBody.rows.length > 0
...
</script>
已保存此调整 here
我的大学作业是使用 HTML、XSL、XML 和 Javascript 创建购物车。我决定使用 XML/XSL 和 Javascript。
我已经设法让 table 与我的基本结构的 javascript 按钮一起显示。我的问题是,如何使用 javascript 函数中的 XML 数据。
我的代码可以在这里找到:
http://xsltransform.net/3Nqn5Yo/11
javascript 代码目前只是占位符,因为它不起作用。我想解决的是如何在 Javascript 函数 "function AddtoCart(name,description,price)".
中使用我的 XML 数据我刚刚在此处调整了您的代码:http://xsltransform.net/3Nqn5Yo/12
如果你想在每个 AddToCart()
调用中直接拥有 XML 数据,调整如下:更改 previous
<button type="button" onclick="AddtoCart('$Product','$Description','$price')">
进入
<button type="button" onclick="AddtoCart('{Product}','{Description}','{price}')">
Add one to cart
</button>
使用 {}
在转换时计算变量。
示例结果:
<button type="button" onclick="AddtoCart('Belts (F)','Woven Finish Fashion Belt','£21.99')">
Add one to cart
</button>
其他详细信息 - 正如我注意到的那样,由于此表达式,转换后的脚本将无法运行
while (orderedProductsTblBody.rows.length & gt;
这可以通过将脚本部分编写为 <xsl:text>
并使用 disable-output-escaping="yes"
来处理,如下所示:
<xsl:text disable-output-escaping="yes">
<script>
... // rest of code stays the same as before
<script>
</xsl:text>
结果是
<script>
...
while(orderedProductsTblBody.rows.length > 0
...
</script>
已保存此调整 here