【发布时间】:2014-01-13 14:42:19
【问题描述】:
我使用 HTML、XML 和 XLST 创建了一个表格。我正在使用 for-each 循环创建一个表,该循环插入 xml 文件中的数据。
一旦表格填满数据,我希望每个被点击的单元格都显示对话框消息框。
XML 文件代码:
<person>
<title>Abraham</title>
<slota>Johns</slota>
<slotb>22</slotb>
<slotc>male</slotc>
<slotd>ave road</slotd>
<slote>0384847</slote>
<slotf>shdh@hot.com</slotf>
<slotg>UK</slotg>
</person>
上面是需要插入表中的所有数据的代码。
XSLT 代码:
<table border="1" cellspacing="0">
<tr>
<th bgcolor="DarkGray" >Employee</th>
<th id="cell1" bgcolor="DarkGray">name</th>
<th id="cell2" bgcolor="DarkGray">surname</th>
<th id="cell3" bgcolor="DarkGray">age</th>
<th id="cell4" bgcolor="DarkGray">gender</th>
<th id="cell5" bgcolor="DarkGray">address</th>
<th id="cell6" bgcolor="DarkGray">phone</th>
<th id="cell7" bgcolor="DarkGray">country</th>
</tr>
<xsl:for-each select="persons">
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="slota" /></td>
<td><xsl:value-of select="slotb" /></td>
<td><xsl:value-of select="slotc" /></td>
<td><xsl:value-of select="slotd" /></td>
td><xsl:value-of select="slote" /></td>
<td><xsl:value-of select="slotf" /></td>
<td><xsl:value-of select="slotg" /></td>
</tr>
</xsl:for-each>
</table>
以上是 XSL 文件创建表和使用for-each 循环插入数据的代码。
我创建了一个使用 JavaScript 显示对话框消息框的函数,这里的代码如下:
<script>
function myFunction()
{
alert ("I am an alert box");
}
</script>
当我将此函数放在一个表格单元格中时,我会触发它,例如:
<td onclick="myFunction()"><xsl:value-of select="slota" /></td>.
该函数适用于该行中的每个表格单元格。
有没有办法可以将此函数应用于特定行?
还是因为我使用for-each 循环来创建表?
【问题讨论】:
-
“有没有办法可以将此函数应用到一个特定的行?” 您的问题不清楚:在您的示例中,XML 输入只有一行。 可以将
onclick属性仅应用于特定行的单元格 - 但是如何识别该行?
标签: javascript html xml xslt