我有一个表格,其中填充了依赖于前一页的值 那些 avlues 显然充满了支柱
但我不是很擅长所有这些东西,所以有没有一个简单的方法可以做这样的事情,要么只使用 HTML,要么我可以在页面中放入一个小的 javascript?
<Table>
<TR>
<TH>ID</TH>
<TD><s:property value="groupID" /><TD> <--Number generated by the page with struts
</TR>
<TR>
<TH>ID Value</TH>
<TD>foobar</TD> <-- the text I want to add in dependant on the number from the previous TD
</TH>
</Table>
那么,有没有一种简单的方法可以做到这一点?也许是 HTML、CSS、JavaScript 解决方案?
最佳答案
给定确切的 HTML,一个像这样的简单脚本就可以做到。但是,如果您不了解 JavaScript,则应该真正学习它,以便了解自己在做什么。
<body>
<Table>
<TR>
<TH>ID</TH>
<TD><s:property value="groupID" /><TD>
</TR>
<TR>
<TH>ID Value</TH>
<TD>foobar</TD>
</TR>
</Table>
<!-- The script is here so it won't run until the TABLE has loaded -->
<script type="text/javascript">
// This is a map of the struts values to your values
var valueMap = {
"1": "foo",
"2": "bar",
"3": "baz"
};
// Browser compatibility. Older IE uses 'innerText' instead of 'textContent'
var textContent = ('textContent' in document) ? 'textContent' : 'innerText';
// Get all the TD elements on the page
var tds = document.getElementsByTagName('td');
// Get the text content of the first TD (index 0)
var text = tds[0][textContent];
// Get the value from the map using the text we fetched above
var value = valueMap[text];
// Set the text content of the second TD (index 1) to the mapped value
tds[1][textContent] = value;
</script>
</body>
关于javascript - 从以前的 TD 设置 TD 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13071733/