How to run a function when the page is loaded?

How to run a function when the page is loaded?

window.onload = codeAddress; should work - here's a demo, and the full code:

方法1

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function codeAddress() {
alert('ok');
}
window.onload = codeAddress;
</script>
</head>
<body> </body>
</html>

方法2

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function codeAddress() {
alert('ok');
} </script>
</head>
<body onload="codeAddress();"> </body>
</html>
上一篇:Ubuntu 14.04 安装 VirtualBox


下一篇:C#实现二维码功能,winform 以及 asp.net均可以用