2014-04-25 2 views
-3

30 초 후이 스크립트를 자동 변경하려고하는데 jquery가 좋지는 않지만 시도해 봐. 이것은 .php 페이지에 있습니다. 다른 폴더에서 자바 스크립트를 가져 오는 데 사용하고 있습니다.jquery 스크립트를 만들었습니다.이 스크립트를 자동 전환하는 방법에 대한 도움이 필요합니다.

<div id="subnavi"> 
<div id="subnavi-user"> 
<div style="margin-top:7px"><b>Fact:</b> <script language="JavaScript"> 

var r_text = new Array();  
r_text[0] = "{hotelName} was founded in 2011 by Kyle"; 
r_text[1] = "{hotelName} strives to remain as professional as possible.";  
r_text[2] = "{hotelName} will only keep on growing if you vote daily!";        
r_text[3] = "Purchasing VIP in the forums helps with the monthly server costs."; 
r_text[4] = "{hotelName} Is a new and developing RP!"; 

window.setInterval(function(){ 

var i = Math.floor(4 * Math.random()) 


document.write(r_text[i]); 

var random = r_text[1]; 

}, 5000); 





</script> 
</div> 

</div> 

<div id="subnavi-search"> 
<div id="subnavi-search-upper"> 
<ul id="subnavi-search-links"> 
<li><a href="{url}/logout" style="color:#000">Sign Out</a></li> 
+1

여기 정확히 목표는 무엇입니까? 타이머에서 전환하려고합니까? 또는 버튼을 클릭 할 때? – attila

+0

나는 타이머에 그것을 원한다. 나의 잘못은 분명하지 않다. – Kyleeck

+0

자바 스크립트의 setInterval을 찾고 있다고 생각합니다. – attila

답변

0

나는 이것이 당신이 찾고있는 경우 확실하지 오전하지만 여기있다 : 이 스크립트는 페이지를 다시로드 할 때마다 실행됩니다. 다른 방법으로 작업해야하는 경우 질문을 업데이트하면 스크립트가 업데이트됩니다. 배열은 5 개 그것의 요소하지 4

을 가지고 있기 때문에

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
<script> 
var r_text = new Array(); 
r_text[0] = "Hello"; 
r_text[1] = "Test"; 
r_text[2] = "We are the lions"; 
r_text[3] = "Fight"; 
r_text[4] = "Switch!"; 

window.setInterval(function(){ 
    var i = Math.floor(5 * Math.random()) 
    var random = r_text[i]; 

    $('#r_text').html(random); 
}, 5000); // you can change the interval here 

는 일부

<div id="r_text"></div> 

확인이 밖으로 here

업데이트Math.floor을 변경 HTML 5로 계산합니다 업데이트 2 귀하의 파일은 다음과 유사해야합니다.

<!Document html> 
<head> 
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script> 
<script> 
var r_text = new Array(); 
r_text[0] = "Hello"; 
r_text[1] = "Test"; 
r_text[2] = "We are the lions"; 
r_text[3] = "Fight"; 
r_text[4] = "Switch!"; 

window.setInterval(function(){ 
    var i = Math.floor(5 * Math.random()) 
    var random = r_text[i]; 

    $('#r_text').html(random); 
}, 5000); // you can change the interval here 
</script> 
</head> 
<body> 
    //Add your html/php code here and pick a place where to show the response of your function. Something like <div id="r_text"></div> 
</body> 
</html> 
+0

나는 그것의 깔끔한 컷을 좋아하지만 30 초 정도 후에 r_text 자동 변경을 만들기 위해 거리를 찾고있다. – Kyleeck

+0

업데이트 확인 – Geo

+0

어떤 이유로 텍스트가 내 페이지에 표시되지 않을 것이며 더 이상 내 전체 PHP 페이지의 더 나은 게시물을 만들 것입니다. – Kyleeck

관련 문제