2014-08-29 4 views
0

웹 페이지의 코드는 특정 버튼을 클릭합니다 :어떻게 매 초마다

<div id="content"> 
    <div class="container-fluid"> 
     Slots 
     <p>The current jackpot is 23220!<p/> 
     <p>You lose.</p> 
     <form method=post action=/games/slots.php> 
      <input type=hidden name='hash_sub' value='MjEzOA=='> 
      <input type=hidden name='act' value='spin'> 
      <input type=submit value='Spin again!'> 
     </form> 
     <a href='slots.php'>Go Back</a> 
    </div> 
</div> 

내 코드 :

setInterval(function solo() { 
    jQuery('content').children('submit[value="Spin again!"]').click(); 
}, 1000); 

나는, 페이지가로드하지만 버튼을 잃었하지 않도록 것입니다 전혀 클릭되지 않았습니다. 콘솔 로그 오류가 없습니다.

+0

는 사용 jQuery를 ('# 콘텐츠') http://jsfiddle.net/8zj4ez7w/ –

답변

0

같이해야한다. .children()은 바로 자식을 가로 지르며 .find()은 자손을 조사합니다. 당신이 children('submit[value="Spin again!"]')를 사용할 때

사용

setInterval(function() { 
    jQuery('#content').find('input[type=submit][value="Spin again!"]').click(); 
}, 1000); 

또한이 값 Spin again!submit 요소를 찾습니다.

DEMO

+0

어떤 이유로이 대신 작동, setInterval (function solo() { jQuery ('# content'). find ('input [type = "submit"] : nth-child (3)') .click(); console.log ("1"); }, 1000); – Emi

+0

@TonyVu 왜': nth-child (3)'를 사용하고 있습니까? – Satpal

+0

Google의 Chrome 콘솔 CSS 경로를 사용하여 요소를 검사 한 결과 #content> div.container-fluid> center> form> input [type = "submit"] : nth-child (3)가 반환되었습니다. – Emi

0

컨텐츠 사업부의 선택이 잘못된 것입니다, 당신이 ID와 #.find() 대신 .children()을 사용하기 위해 필요한이

setInterval(function solo() { 
jQuery('#content').children('submit[value="Spin again!"]').click(); 
}, 1000); 
+0

내가 해시 태그를 추가하는 시도하지만 식별 차이가 없습니다를 참조하십시오. 새로 고침/페이지를 다시 입력하면로드 된 후에 아무 일도 일어나지 않습니다. – Emi