I want to 실행하십시오 기능을 사용할 수 있지만, 해당 페이지를 보면 로드되었는지 살고싶지않다구요 ',' 태그이고, body> <.
I have a ',' 내가 만약 초기화 런입니다 스크립트입니다 이를 다음과 같이 body> <.
function codeAddress() {
// code
}
<body onLoad="codeAddress()">
하지만 난 로렌아줌마가 'body onload = " < 없이 실행할지,, 나도 날잡아' 와 > " 코디드레스 () 이 많은 것들 (예::
window.onload = codeAddress;
그러나 그것은 작동안함.
그럼 어떻게 실행합니까 때 이 페이지가 로드되었는지?
',' = 코디드레스 빈다우드로 로이드 노력해야 한다는 - [here& # 39 의 데모] (
), 그리고 전체 코드:<! - begin 스니핏: js 숨기십시오: > 거짓값 -;
<!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>
끝 - < 스니핏 >;!
<! - begin 스니핏: js 숨기십시오: > 거짓값 -;
<!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>
끝 - < 스니핏 >;!
Jquery 또는 빈다우드로 로이드 훌륭한 기능을 사용하지 않고, jQuery 의 기본 JavaScript 릴리스부터는 채택하였다. 이제 모든 현대 브라우저의 DOM 준비됐어들 사용하지 않고 자체 라이브러리 함수를 포함한다.
document.addEventListener('DOMContentLoaded', function() {
alert("Ready!");
}, false);
'빈다우드로 로이드 = 함수 () {'. 등의 오토메이티드 멋지구리해요 아닙니다.
이 일을 하지만 또 다른 함수 후킹 이미 분할합니다 가능성이 있는 경우이다. 당신, 후에 다른 함수를 경우에는 해당 이벤트 후크를 agent. 네거잖아 분할합니다 방침이다. 그러니까 왜 많이 투자할 수 시간 후, t # 39 더 이상 isn& 일하던 생각하신거야 위해 애쓴다.
보다 강력한 오토메이티드 [1] [here:]
if(window.attachEvent) {
window.attachEvent('onload', yourFunctionName);
} else {
if(window.onload) {
var curronload = window.onload;
var newonload = function(evt) {
curronload(evt);
yourFunctionName(evt);
};
window.onload = newonload;
} else {
window.onload = yourFunctionName;
}
}
저는 그동안 일부 코드를 사용하여 만든 이에게 크레딧보다 잘 안 어디서 찾았어.
function my_function() {
// whatever code I want to run after page load
}
if (window.attachEvent) {window.attachEvent('onload', my_function);}
else if (window.addEventListener) {window.addEventListener('load', my_function, false);}
else {document.addEventListener('load', my_function, false);}
이렇게 하면 좋겠네요:)
시행하십시오 설정할 수 있는 동리디 스크립트입니다 에 대해 다양한 기능을 실행할 때 DOM 은 로드됨. # 39 의 JavaScript 가 기본적으로 어떤 it& Dom 준비됐어들 널리 사용되는 라이브러리, 그러나 경량일 너회의 개외부 스크립트입니다 시작할 때 취할 수 있는 파일 및 말했다.
사용 예제
// add reference to domReady script or place
// contents of script before here
function codeAddress() {
}
domReady(codeAddress);
이렇게 빈다우드로 로이드 작동합니다.
<! - begin 스니핏: js 숨기십시오: 거짓값 콘솔: 진정한 바벨. > 거짓값 -;
function codeAddress() {
document.getElementById("test").innerHTML=Date();
}
window.onload = codeAddress;
<!DOCTYPE html>
<html>
<head>
<title>learning java script</title>
<script src="custom.js"></script>
</head>
<body>
<p id="test"></p>
<li>abcd</li>
</body>
</html>
끝 - < 스니핏 >;!
[리디국가창레] 시도하시겠습니까 (https://javascript.info/onload-ondomcontentloaded)
document.addEventListener('readystatechange', () => {
if (document.readyState == 'complete') codeAddress();
});
여기서 상태는 다음과 같습니다.
<! - begin 스니핏: js 숨기십시오: 진정한 콘솔: 거짓값 바벨. > 거짓값 -;
<script>
document.addEventListener("DOMContentLoaded", () => {
mydiv.innerHTML += 'DOMContentLoaded' + '</br>';
});
window.onload = () => {
mydiv.innerHTML += 'window.onload' + '</br>';
} ;
document.addEventListener('readystatechange', () => {
mydiv.innerHTML += 'ReadyState: '+document.readyState + '</br>';
if (document.readyState == 'complete') codeAddress();
});
function codeAddress() {
mydiv.style.color = 'red';
}
</script>
<div id='mydiv'></div>
끝 - < 스니핏 >;!
스케쳐내 때 함수를 실행하여 바디입니다 로드되는지. 대신, 할 수 있는 onload 속성용 확증하노라 태그번호 몸에 좋아.
<! - begin 스니핏: js 숨기십시오: 거짓값 콘솔: 진정한 바벨. > 거짓값 -;
// define the body
var body = document.getElementsByTagName("body")[0];
// or
// var body = document.querySelector("body");
// or
// var body = document.querySelectorAll("body")[0];
function codeAddress() {
// your function
alert("Hello World");
}
body.onload = function() {
codeAddress();
};
<!DOCTYPE html>
<html>
<head>
<title>learning java script</title>
</head>
<body>
<h1>Sample Heading</h1>
<p>Sample text</p>
</body>
</html>
끝 - < 스니핏 >;!