Re: [請問] 這個要怎麼一次只顯示一個

看板Ajax作者 (我還想要更多力量)時間15年前 (2010/06/08 18:48), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《knives ()》之銘言: : ※ [本文轉錄自 EZsoft 看板 #1C3CF9Vh ] : 作者: knives () 看板: EZsoft : 標題: [請問] 這個要怎麼一次只顯示一個 : 時間: Mon Jun 7 18:02:46 2010 : <div id="hot_news"> : <p style=" "><a href="" rel="nofollow">http://tw.yahoo.com">第一個</a></p> : <p style=" "><a href="" rel="nofollow">http://www.google.com.tw">第二個</a></p> : <p style=" "<a href="http://www.yam.com.tw" >第三個</a></p> : <p style=" "><a href="http://www.yam.com.tw" >第四個</a></p> : </div> : 我的js : function marquee() : { : var container=document.getElementById("hot_news"); : container.appendChild(container.firstChild); : } : setInterval("marquee()",3000); : 這樣子會產生類似跑馬燈的效果 : 但是我要怎麼樣才能夠一次只顯示一個 : 另外如果換用jquery寫要怎麼寫阿 : 謝謝 <div id="hot_news"> <p style="display:none;"><a href="" rel="nofollow">http://tw.yahoo.com">第一個</a></p> <p style="display:none;"><a href="" rel="nofollow">http://www.google.com.tw">第二個</a></p> <p style="display:none;"><a href="http://www.yam.com.tw" >第三個</a></p> <p style="display:none;"><a href="http://www.yam.com.tw" >第四個</a></p> </div> <script> var i=0; var links = document.getElementById('hot_news').getElementsByTagName('p'); setInterval(function(){ for(var n=0 ; n<links.length ; n++){ if(i === n){ links[n].style.display = 'block'; } else { links[n].style.display = 'none'; } } ++i; i = i >= links.length ? 0 : i; },1000); </script> 參考看看吧 -- 到底是…     創造了?              相信上蒼,就別褻瀆神明! ________________________________________________________________________________  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄         亦或是…            相信自己,就別妄自菲薄!             創造了? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 122.116.88.75
文章代碼(AID): #1C3Y0P9H (Ajax)
文章代碼(AID): #1C3Y0P9H (Ajax)