JS新增HTML

動機:想要以javascript新增跑馬燈內容

http://dotnetmis91.blogspot.com/2009/03/blog-post_07.html


<!-- 跑馬燈內容 from 試算表 -->

<div id="news">

<!-- 這裡放增加的項目 -->

</div>

<script>

//甄選科目

var subject = returnPara.subject;

for (var i=0;i<subject.length;i++){

  var str = subject[i];

  var newItem = document.createElement("li");

  var itemText = document.createTextNode(str);

  newItem.appendChild(itemText);

  document.getElementById("news").appendChild(newItem);

}

<!-- jQuery跑馬燈 -->

$(document).ready(function(){

  setInterval(function(){

    $('#news li:first-child').slideUp(function(){      $(this).appendTo($('#news')).slideDown()

    })      

  },3000)

})

</script>

chatGPT的建議

$(document).ready(function() {

 function scrollMarquee() 

  { $("#marquee li:first").slideUp(function() {

    $(this).appendTo($("#marquee")).slideDown(); 

  }); 

 } 

// 設定跑馬燈捲動的時間間隔,這裡設定為3秒 

var scrollInterval = setInterval(scrollMarquee, 3000); }); 


參考文獻:https://ithelp.ithome.com.tw/articles/10218607

https://dic.vbird.tw/webdesign/main2017/unit13.php