이 jQuery 함수를 페이지로드에 대한 addtition에서 실행하고 싶습니다. 같은두 이벤트에 대한 jQuery
jQuery(document).ready(function() {
뭔가 : 이것은 당신을위한 해결책이 될 수
jQuery(document).ready OR $(window).resize(function() {
이 jQuery 함수를 페이지로드에 대한 addtition에서 실행하고 싶습니다. 같은두 이벤트에 대한 jQuery
jQuery(document).ready(function() {
뭔가 : 이것은 당신을위한 해결책이 될 수
jQuery(document).ready OR $(window).resize(function() {
. 당신 resize
페이지
$(document).ready(runMyFunction);
$(window).on('resize', runMyFunction);
function runMyFunction() {
// do whatever
}
명명 된 함수를 정의하고 두 이벤트에 대한 콜백으로 설정하면 두 페이지가 ready
때 또는
기능 runMyFunction
가 실행됩니다.
function callback(){
// ....
};
$(document).ready(callback);
$(window).resize(callback);
jQuery를 초기화하는 권장 구문은 .ready()
기능을 사용하지 않는 것입니다.
function toBePerformedOnLoadAndResize(){
// Your code here
}
$(function(){
// The above is the suggested replacement for
// "$(document).ready(function(){
// Run it now
toBePerformedOnLoadAndResize();
// Run it on resize as well
$(window).resize(toBePerformedOnLoadAndResize);
// Your Other Code
});
소스 jQuery API documentation : jQuery를 3.0로
는 만$(handler)
권장; 다른 구문은 여전히 작동하지만 더 이상 사용되지 않습니다. 이는 선택 항목이 .ready() 메서드의 동작에 영향을 미치지 않아 비효율적이며 메서드 동작에 대한 잘못된 가정을 초래할 수 있기 때문입니다. 예를 들어,$("document").ready(handler)
은 "문서"와 함께 작동하여 아무것도 선택하지 않습니다.$("img").ready(handler)
은 문서가 준비 될 때까지 기다리지 만 이미지가 준비 될 때까지 기다리는 것을 의미합니다 (잘못).