I want to run a function when the page is loaded, but I don't want to use it in the <body>
tag.
(我想在页面加载时运行一个函数,但我不想在<body>
标签中使用它。)
I have a script that runs if I initialise it in the <body>
, like this:
(如果我在<body>
初始化它,我会运行一个脚本,如下所示:)
function codeAddress() {
// code
}
<body onLoad="codeAddress()">
But I want to run it without the <body onload="codeAddress()">
and I have tried a lot of things, eg this:
(但是我想在没有<body onload="codeAddress()">
情况下运行它,我尝试了很多东西,例如:)
window.onload = codeAddress;
But it is not working.
(但它没有用。)
So how do I run it when the page is loaded?
(那么如何在加载页面时运行它?)
ask by Claes Gustavsson translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…