javascript - XSL + Java 脚本问题...无法从 xsl 文件调用 javascript 函数

标签 javascript xml

我是 XSL 世界的新手,遇到了一些 XSL 问题

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">

<xsl:template match="/">
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <link rel="stylesheet" type="text/css" href="mycss.css" />
        <script language="javascript"  type="text/javascript" >
                      <xsl:text></xsl:text>
        </script>

        </head>
    <body>

    <table>
        <tr bgcolor='yellow' onMouseover="changeColor(event, 'red');"> MYTEXT 
        </tr>
    </table>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

我的 XML 文件是

<COUNTRY>
        <CITY>X</CITY>
        <CITY>Y</CITY>
</COUNTRY> 

我的 Javascript 文件是

   function changeColor(e,highlightcolor){
      source=ie? event.srcElement : e.target
      source.style.backgroundColor=highlightcolor
   }

问题不是鼠标悬停,颜色在浏览器中没有改变......

最佳答案

在您的 XSL 中,我没有看到包含任何 JavaScript 文件 (.js),也没有看到您提到的 javascript 函数。其次,您在函数 changeColor 中使用的 ie 变量定义在哪里?

检查通过在浏览器上查看源代码生成的 html,看是否一切正确。在您的函数中添加一些警报以确认它是否真的被调用。

关于javascript - XSL + Java 脚本问题...无法从 xsl 文件调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/796190/

相关文章:

javascript - 在 html 正文中使用脚本变量

javascript - Js linq : group by 2 properties

java - XML 编码 + 项目结构

Java 在单个 JTable 单元格中显示元素

javascript - 在 Microsoft Azure 移动服务 Javascript 中解析 XML?

java - 使用字符串生成器将 XML 放入单个 csv/xls 列中不起作用

javascript - 如何从字符串中删除最后一个 '[]'?

javascript - 如何设置CSS规则只适用于iPhone浏览器而不使用JS?

JavaScript:如何生成随机字母表,其中某些单词随机隐藏?

xml - XSLT 合并多个条目并将数字相加