我在xul文件中有js,我想从主窗口调用特定的功能

时间:2011-11-22 16:23:41

标签: javascript javascript-events xul

现在我将尝试提及我的问题:

我的javascript文件中有一个名为playIt()的函数。

这是javascript文件:

playIt(){
    alert("yes it work!");
}

此javascript代码位于XUL文件中。

我有这个源代码:

<html>
<head>
<title>this is title</title>
</head>
<body>
<div id="clickIt" onclick="javascript:playIt();">
</body>
</html>

但问题是当我点击div并且函数没有启动时没有任何反应。

1 个答案:

答案 0 :(得分:2)

更好的方法是在内容加载后附加事件。

https://developer.mozilla.org/en/Code_snippets/On_page_load

// do something with the loaded page.行之后

添加自己的代码

doc.getElementById('clickIt').addEventListener('click',playIt,false);

编辑:
在任何事情之前从onclick属性中删除javascript:并重新测试!!

相关问题