开发者

Javascript function getting called only on event!

开发者 https://www.devze.com 2022-12-25 14:08 出处:网络
I have a javascript function, I want it to be called programatically on init and later onClick event but its not getting called programatically but works ok with onClick.

I have a javascript function, I want it to be called programatically on init and later onClick event but its not getting called programatically but works ok with onClick.

The example would be:

开发者_如何学C
function init() {
  a(); 
}

init() is called on initialization which should call a() but thats not happening!


Here is the example working 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>
0

精彩评论

暂无评论...
验证码 换一张
取 消