2010-04-01 47 views
0

我有一个JavaScript函数,我希望它在初始化和以后的onClick事件中以编程方式调用,但它没有通过编程方式调用,但可以与onClick一起使用。仅在事件中才会调用Javascript函数!

的例子是:

function init() { 
    a(); 
} 

init()被称为在初始化应该叫a()但那不会发生!

+0

有实在不够去这里的例子。函数a()的代码可能会更有帮助,以及您收到的任何调试/错误消息。 – 2010-04-01 09:03:30

回答

2

这里是工作的100%

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title>sdasddss</title> 


    <script type="text/javascript"> 
    function init(){ 
alert("I'm calling afunction()"); 
afunction(); 
} 

function afunction(){ 
alert("I was called successfuly"); 
} 

window.onload = init; 
    </script> 

</head> 

<body> 

My body 

</body> 
</html> 
相关问题