JavaScript로 스크립팅하는 중에 궁금한 점이 있었으며 이해하는 방식이 올바른지 확실하지 않습니다. 기본적으로 나는 두 번째 버튼이 처음으로 끌어 올려지지 않으면 루프를 종료해야하는 버튼을 클릭하고 싶습니다.첫 번째 호출시 버튼 요소가 검색되지 않습니다.
var intervalID = window.setInterval(myfunc,1000);
function t(){
console.log('quit');
clearInterval(intervalID);
}
function myfunc(){
//first button
document.getElementsByClassName('hit')[0].click();
//try to retrieve the second one
var el = document.getElementsByClassName('hit_ok');
console.log(el.length);
//if it exists click it
if (el.length == 1){
el[0].click();
//otherwise exit
} else {
console.log('ready to quit');
window.setTimeout(t,50);
}
}
내 문제는 첫 번째 인스턴스가 항상 0을 반환한다는 것입니다 문 내가 또한 다음을 시도하는 경우 :
function myfunc(){
document.getElementsByClassName('hit')[0].click();
var el = document.getElementsByClassName('hit_ok');
console.log(el);
if (el != null){
el[0].click();
} else {
console.log('ready to quit');
window.setTimeout(t,50);
}
}
사실이 반환
[] -> 길이 : 0__proto__ : HTMLCollection
VM3642 : 1 잡히지 않는 TypeError : 정의되지 않은 'click'속성을 읽을 수 없습니다.
,363,210는 대신 :
는[span.hit_ok]
처음가 검색 버튼 질수 있다는 것을 의미한다. 첫 번째 버튼을 누른 후 두 번째 버튼이 분명히 있습니다.
HTML 코드 :
//first button
<div class="try">
<input type="hidden" id="isHit" value="">
<a href="javascript:void(0);" class="hit">Try</a>
</div>
//second button
<div class="msgbox_button">
<span class="hit_ok" onclick="remove();">OK</span>
</div>
어떤 아이디어? 당신이 무엇
감사합니다,
로드 된 후 루프를 시작합니다. 나는 뭔가를 놓친다는 것을 안다. – user217354
HTML? 당신이 거기 sth 엉망이 된 것 같습니다 ... –
문제를 설명하는 작동 예제를 추가 할 수 있습니까? –