倒計時定時跳轉

帶3秒倒計時定時跳轉
(第一種適合固定一個頁面的跳轉,第二種適合多個頁面的跳轉,只要保持id名稱一致,修改URL,直接導入js文件)
第一種:
<script>
  function to() {
   var timeSpan = document.getElementById("time");
   var t = parseInt(timeSpan.innerHTML) - 1;
    timeSpan.innerHTML = t;
    if (t == 0) {
     window.location.href = "index.html";
    }
   }
   setInterval(to, 1000);
 </script>
  
 
 
 第二種: 
  
  <script>
   function toPage(url) {
    if (url) {
     window.location.href = url;
    }
   }

   function changTime() {
    var timeDom = document.getElementById("time");
    var time = parseInt(timeDom.innerHTML);
    if (0 == time) {
     clearInterval(timeId);
     var targetDom = document.getElementById("targetPage");
     toPage(targetDom.href);
    } else {
     timeDom.innerHTML = --time;
    }
   }
   var timeId = setInterval("changTime()",1000);
  </script>
  
  
不帶倒計時定時跳轉  
<script>
 function toPage(url){
  if (url) {
   window.location.href = url;
  }
   
 }
  setTimeout("toPage('index.html')",3000);
 </script>
  

  

刪除按鈕:
 <a href="javascript:deleteRecords('id','#');" class="like_btn">刪除</a>
 <script>
  //刪除一組記錄
  function deleteRecords(checkboxName, deleteUrl) {
   //根據表單名字來獲得一組對象
   var oChecks = document.getElementsByName("id");
   //定義一個數組,放置選中的checkbox的value值
   var ovalues = [];
   for (var i = 0; i < oChecks.length; i++) {
    if (oChecks[i].checked == true) {
     ovalues.push(oChecks[i].value);
    }
   }
   if (ovalues.length == 0) {
    alert("請選擇要刪除的記錄")
   } else {
    var b = confirm("您確定要刪除選中的記錄嗎?");
    if (true == b) {
     var params = ''; //請求參數
     for (var i = 0; i < ovalues.length;i++) {
      params = params + "id=" + ovalues[i] + "&";
     }
     //刪除提交到deleteURl刪除
     window.location.href = deleteUrl + "?" + params;
    }
   }
  }
 </script>
 
 

伸縮菜單

 <h1 class="sup-menu">產品管理</h1>
   <ul class="sub-menu" style="display: none;">
 <script>
  //父菜單項
  var supMenus = document.getElementsByClassName("sup-menu");
  //子菜單項
  var subMenus = document.getElementsByClassName("sub-menu");
  
  for (var i = 0; i < supMenus.length; i++) {
   //拿出每個父菜單
   var supMenu = supMenus[i];
   //將父菜單和緊跟的子菜單做一個綁定,用到了JavaScript的動態語言特徵
   supMenu.subMenu = subMenus[i];
   //註冊事件監聽
   supMenu.onclick = function(){
   // this指向對應的元素對象
    if (this.subMenu.style.display=="none") {
     this.subMenu.style.display='';
    } else{
     this.subMenu.style.display="none";
    }
   }
  }
 </script>
 
 
 表格獲得高亮的效果
 function hightlightShow() {
   //獲得高亮顯示錶格對象
   var listTb = document.getElementById("list_tb");
   //獲取表格所有行
   var ostr = listTb.rows;
   for (var i = 0; i < ostr.length; i++) {
    // 排除表格的第0行和最後的2行
    if (i > 0 && i < ostr.length - 2) {
     var str = ostr[i];
     //註冊鼠標的懸停事件
     str.onmouseover = function() {
       this.style.backgroundColor = "#FFF8DC";
      }
      //註冊鼠標的離開事件
     str.onmouseout = function() {
      this.style.backgroundColor = '';
     }
    }
   }
  }
  //執行函數
  hightlightShow();

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章