在HTML中的指定表格单元格中显示消息对话框

在HTML中的指定表格单元格中显示消息对话框

本文介绍了在HTML中的指定表格单元格中显示消息对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i have created a table using HTML, XML and XLST. the I am creating a table using a for-each loop which inserts the data from the xml file.
Once the table is filled with data, i would like every cell that is clicked to display dialogue message box.

Code for XML file:

    <person>
        <title>Abraham</title>
        <slota>Johns</slota>
        <slotb>22</slotb>
        <slotc>male</slotc>
        <slotd>ave road</slotd>
        <slote>0384847</slote>
        <slotf>[email protected]</slotf>
        <slotg>UK</slotg>
      </person>

Above is the code with all the data needed to be inserted into the table.

XLST Code:

    <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>

Above is the code for xsl file creating the table and inserting data using the for-each loop.

I have created a function that displays a dialog message box using java script and here the code below:

    <script>
        function myFunction()
        {

          alert ("I am an alert box");
          }
          </script>

when i place this function in a table cell that i would it to be triggers it for example:

    <td onclick="myFunction()"><xsl:value-of select="slota" /></td>.


The function applies to each and every table cell in that row.

Is there a way i can apply this function to one specific cell?
or is because i am using a for-each  loop to create the tabel?

I hope this makes sense..

and thank you in advance.

推荐答案


这篇关于在HTML中的指定表格单元格中显示消息对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 23:20