遇到 xsl 相关问题 【100分】

rqx110 2009-07-06 04:56:48
Hi, I'm having a problem running a javascript function which is embedded in an XSLT and invoked with the body onload event.
Here is the xml, test.xml:


<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<foo></foo>


And here is the xsl, test.xsl:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html>
<head>
<script language="javascript" type="text/javascript">
function init () { alert("It worked!"); }
</script>
</head>
<body onload="init();">
<button onclick="init();">Click me</button>
</body>
</html>

</xsl:template>
</xsl:stylesheet>


When the xml page loads, there is no alert box which should pop up. However, when I click the button that points to the same javascript function, it works fine. In addition, there is a "init not defined" error message in the error console. I suspect it has something to do with Firefox not having interpreted the javascript before the body onload event is triggered.

This code works fine in IE7--the alert box pops up when the page is initially loaded and when the button is clicked, but I would like to get it to run in Firefox. Any insight or fixes, or maybe pointers to the proper way of invoking javascript are welcome.



----------------------------
觉得分少的 我可以再加
...全文
48 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
rqx110 2009-07-08
  • 打赏
  • 举报
回复
不研究这问题了,直接结贴完事
yanlong521521 2009-07-06
  • 打赏
  • 举报
回复
没见到过,学习下,帮顶个
byxxw 2009-07-06
  • 打赏
  • 举报
回复
我这里 FireFox下面没有问题
jzywh 2009-07-06
  • 打赏
  • 举报
回复
<script language="javascript" type="text/javascript">
<![CDATA[
function init () { alert("It worked!"); }
]]>
</script>
stromboy007 2009-07-06
  • 打赏
  • 举报
回复
SF 帮顶·~~ IE可以?火狐不行??

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧