Javascript function getting called only on event!
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:
开发者_如何学Cfunction 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>
精彩评论