window.load
& document.ready
뒤에로드되는 HTML 페이지의 요소에 어떻게 액세스합니까?dom에서 window.load 이후에로드되는 요소에 액세스하기
jQuery 문서 준비 또는로드를 사용하여 액세스 할 수 없습니다.
window.load
& document.ready
뒤에로드되는 HTML 페이지의 요소에 어떻게 액세스합니까?dom에서 window.load 이후에로드되는 요소에 액세스하기
jQuery 문서 준비 또는로드를 사용하여 액세스 할 수 없습니다.
이벤트에 액세스해야하거나 이벤트가 도착할 때 사용할 수있는 이벤트가있는 경우 해당 이벤트를 사용하십시오. 당신이에 연결할 수없는 이벤트가없는 경우
, 당신은 타이머 루프 (그들에게 예를 들면, 폴링)를 사용하여 표시하도록 기다릴 수 : 요소에 액세스 할 트리거를 사용하는 가정
(function() {
function doSomething() {
var elements = $("selector-for-the-elements");
if (!elements.length) {
// Not there yet, keep waiting
setTimeout(doSomething, 100); // 100ms = 1/10th second, adjust as needed
return;
}
// We have them, use them
}
$(doSomething); // Make the first call happen on document ready
})();
을의 작동 다음
$("<trigger>").on("click", function() {
<access loaded element>
});
$(".parent_class").on("click",".the_element_you_need",function() {
//code here
});
로드 이벤트가 있습니까? 클릭 이벤트가 페이지에 없습니다. – user3555971
$(document).on("click",".your_element",function() {
//do something
});
이미 jQuery를 언급 한 이후
, 나는 당신에게 jQuery를 특정 대답을 줄 것이다 :
$("body").on("click",".selector-late",function(e){
//Your Code Here.
//e.delegateTarget returns the body element.
//e.currentTarget returns .selector-late element.
//e.target returns the element which was clicked. (could be a child of .selector-late too)
});
설명 :
body
이 요소의 부모 일 수 있습니다.)click
은 내가 첨부 한 이벤트입니다. 요구 사항에 따라 변경할 수 있습니다..selector-late
은 언제든지로드 될 수있는 요소의 선택 자입니다.이 방법은 detail here.
@ user3555971 - 행운을 빕니다. –
에 설명되어
서명으로 설명 example..If의 수 – user3386779
당신이 JS를 통해 동적 HTML 요소를 액세스에 대해 얘기 바이올린을 만드십시오? – Sarath