帮助更改HTML表中的行颜色,从XML文件读取 [英] Help with Changing Row Color in a HTML Table, Reading from XML File

查看:87
本文介绍了帮助更改HTML表中的行颜色,从XML文件读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个HTML页面,该页面显示书籍"以及它们的状态,如有货",无货",即将到货"或预购". HTML页面从XML文件读取此信息.片段如下:
HTML

I have an HTML page that displays Books and their status as to whether they are In Stock, Out of Stock, Arriving Soon, or Preorder. The HTML page reads this information from a XML file. Snippets are below:
HTML

<body>
<table width="30%" border="0" align="left" cellspacing="1" font size="10">
  <tr bgcolor="#CCCCCC">
    <td colspan="2">
<table width="100%"  datasrc="#nb_fict" font size="1" border="0" align="center" bordercolor="#FFFFFF">
<caption>
<span>Fiction</span>
</caption>
<thead>
<tr>
<th span class="style1">ProductID</th></span>
<th span class="style1">Title</th></span>
<th span class="style1">Author</th></span>
<th span class="style1">Pub. Date</th></span>
<th span class="style1">Stock</th></span>
<th span class="style1">No. In Stock</th></span>
<th span class="style1">Holding</th></span>
</tr>
</thead>
<tbody>
<tr>
<td><span class="style1" datafld="prodID"></td></span>
<td><span class="style1" datafld="Title"></td></span>
<td><span class="style1" datafld="Author"></td></span>
<td><span class="style1" datafld="Date"></td></span>


<td><span class="style1" datafld="Stock"></td></span>
<td><span class="style1" datafld="NumberStock"></td></span>
<td><span class="style1" datafld="holding"></td></span>

					
					
				  </tr>
				  </tbody>
				</table>
				
	</td>
  </tr>



现在,根据流派,我有不同的XML文件名.
我要做的是根据库存"字段中的内容更改表中的行颜色.例如,如果它是库存"的IS,则希望它是绿色的.如果它是预购"的订单,我希望它显示为橙色.我假设我可能必须为此使用Java Script,但是我不知道该怎么做.任何帮助将非常感激.谢谢!

哎呀!很抱歉使用回答问题"按钮来发表自己的评论.确实不确定如何执行此操作,但是感谢您让我知道.
如果有人有任何想法,请仔细阅读答案",因为其中一些帖子是我的.

来吧.我知道有人可以回答这个问题.我认为它是如此接近,可能只是我所缺少的一些小东西.任何帮助将不胜感激.



Now, I have have different XML file names by the Genre.
What I want to do is change the row color in the table depending on what is in the Stock field. For example, if it''s IS for "Instock" I want it to be green. If it''s PO for "Preorder" I want it to display orange. I''m assuming I would have to maybe use Java Script for this, but I don''t know how to do it. Any help would be much appreciated. Thanks!

Whoops! Sorry for using the "Answer Question" button for my own comments. Wasn''t really sure how to do that, but thanks for letting me know.
If someone has any ideas, please read through the "answers" as some of those posts were mine.

Come on. I know someone can answer this. I think it''s so close and probably just something small I''m missing. Any help would really be appreciated.

推荐答案

使用asp表,它具有更多的属性和方法...
take asp table it has some more properties and methods...


我会讨厌不得不重新编码所有这些表.
I would hate to have to re-code all those tables. Is there any way it can be done the way I have it?


您好,您可以使用javascript根据特定数据来实现行颜色的更改.您可以像这样在javascript中更改元素的样式:

Hi there, you can use javascript to achieve the changing of row color depending on a particular data. You can change the style of the element in javascript like this:

function changeRowColor {
  el = document.findElementById('elName');
  // then you can add a condition here. if the value of the element is "InStock" then the color is green otherwise set the color to whatever color you prefer.
  // you can set the color of the element using,
  el.style.color = "green";
}


然后您可以在适当的事件中调用此函数.
但是,最有效的方法是使用AJAX.


and then you can invoke this function in the appropriate event.
But, the most effective way of doing this is to use AJAX.


这篇关于帮助更改HTML表中的行颜色,从XML文件读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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