Jquery 解析 XML - 交替行颜色
如何向以下内容添加代码以交替行颜色
parsedata = function(xml){
var str = "";
var cart = xml.documentElement.firstChild;
if(cart.childNodes.length > 0 ){
str = str + '<table border="0" width="100%" cellspacing="0" cellpadding="5">';
str = str + ' <tr><td class="animBoxCartLink" colspan="2"><a href="' + globals.cart_link + '">' + globals.cart_text + '</a></td></tr>
for (var i = 0; i < cart.childNodes.length; i++){
try{name = cart.getElementsByTagName("NAME")[i].childNodes[0].nodeValue;}catch(e){name = "Item";}
try{attributes = cart.getElementsByTagName("ATTRIBUTES")[i].childNodes[0].nodeValue;}catch(e){attributes = "";}
try{llink = cart.getElementsByTagName("LINK")[i].childNodes[0].nodeValue;}catch(e){llink = "";}
try{image = cart.getElementsByTagName("IMAGE")[i].childNodes[0].nodeValue;}catch(e){image = "No Image";}
try{qty = cart.getElementsByTagName("QTY")[i].childNodes[0].nodeValue;}catch(e){qty = "message";}
try{price = cart.getElementsByTagName("PRICE")[i].childNodes[0].nodeValue;}catch(e){price = "$0.00";}
dimension = (globals.cart_image_width ? 'width="' + globals.cart_image_width : '') + (globals.cart_image_height ? '" height="' + globals.cart_image_height + '"' : '');
str = str + ' <tr>';
str = str + ' <td class="animBoxCartImage" width="' + globals.cart_image_width + '" align="center"><a href="' + llink +'"><img src="' + image + '" ' + dimension + ' border="0" alt="' + name + '"></a></td>';
str = str + ' <td class="animBoxCartContent" width="100%">';
str = str + ' <div class="animBoxCartName"><a href="' + llink + '">' + name + '</a><br />' + attributes + '</div>';
str = str + ' ' + globals.text_cart_quantity + ' ' + qty;
str = str + ' <div class="animBoxCartPrice">' + price + '</a></div>';
str = str + ' <a href="' + llink + '"> More Info </a>';
str = str + ' </td>';
str = str + ' </tr>';
.js 文件(Jquery)的前半部分主要涉及位于标题中的购物车的显示/隐藏,我刚刚发布的部分是我的内容我的想法是我需要添加代码,我可以在其中添加样式以便行颜色交替。
How do I add code to the following to alternate the row color
parsedata = function(xml){
var str = "";
var cart = xml.documentElement.firstChild;
if(cart.childNodes.length > 0 ){
str = str + '<table border="0" width="100%" cellspacing="0" cellpadding="5">';
str = str + ' <tr><td class="animBoxCartLink" colspan="2"><a href="' + globals.cart_link + '">' + globals.cart_text + '</a></td></tr>
for (var i = 0; i < cart.childNodes.length; i++){
try{name = cart.getElementsByTagName("NAME")[i].childNodes[0].nodeValue;}catch(e){name = "Item";}
try{attributes = cart.getElementsByTagName("ATTRIBUTES")[i].childNodes[0].nodeValue;}catch(e){attributes = "";}
try{llink = cart.getElementsByTagName("LINK")[i].childNodes[0].nodeValue;}catch(e){llink = "";}
try{image = cart.getElementsByTagName("IMAGE")[i].childNodes[0].nodeValue;}catch(e){image = "No Image";}
try{qty = cart.getElementsByTagName("QTY")[i].childNodes[0].nodeValue;}catch(e){qty = "message";}
try{price = cart.getElementsByTagName("PRICE")[i].childNodes[0].nodeValue;}catch(e){price = "$0.00";}
dimension = (globals.cart_image_width ? 'width="' + globals.cart_image_width : '') + (globals.cart_image_height ? '" height="' + globals.cart_image_height + '"' : '');
str = str + ' <tr>';
str = str + ' <td class="animBoxCartImage" width="' + globals.cart_image_width + '" align="center"><a href="' + llink +'"><img src="' + image + '" ' + dimension + ' border="0" alt="' + name + '"></a></td>';
str = str + ' <td class="animBoxCartContent" width="100%">';
str = str + ' <div class="animBoxCartName"><a href="' + llink + '">' + name + '</a><br />' + attributes + '</div>';
str = str + ' ' + globals.text_cart_quantity + ' ' + qty;
str = str + ' <div class="animBoxCartPrice">' + price + '</a></div>';
str = str + ' <a href="' + llink + '"> More Info </a>';
str = str + ' </td>';
str = str + ' </tr>';
The first half of the .js file (Jquery) pertains mostly to the show/hide of the cart which is located in the header and the portion I just posted is what I'm thinking is where I would need to add code where I can add styles so that the row color alternates.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
保持其余代码相同:
将
str = str + ' ';
替换为:然后您需要为 rowcolors 定义 css 类:
Keeping the rest of your code the same:
Replace
str = str + ' <tr>';
with:Then you need css classes defined for the rowcolors:
我什至不打算尝试解决这个问题。在
tr
上:添加 alt row 类:
I'm not even going to try to fix this. On the
tr
:add alt row class: