溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

jQuery實現(xiàn)Table表格隔行變色及高亮顯示當前選擇行效果示例

發(fā)布時間:2020-09-11 03:23:15 來源:腳本之家 閱讀:313 作者:程序詩人 欄目:web開發(fā)

本文實例講述了jQuery實現(xiàn)Table表格隔行變色及高亮顯示當前選擇行效果。分享給大家供大家參考,具體如下:

最近客戶要求高亮選擇列表的功能,于是順便做了個,作為記錄。

jQuery實現(xiàn)Table表格隔行變色及高亮顯示當前選擇行效果示例

前臺代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>JQuer的鼠標懸浮,鼠標高亮效果</title>
  <style type="text/css">
  #header
  {
    background-color:#00ffff;
    text-align:center;
  }
  .style1
  {
    text-align: right;
  }
  .style2
  {
    text-align: center;
  }
  </style>
  <link href="tables.css" rel="external nofollow" rel="stylesheet" type="text/css" />
  <script src="jquery-1.4.2.min.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(document).ready(function() {
    doChangeColorOfRow("#tableThis tr:even:not(#header)", "#tableThis tr:odd:not(#header)");
    });
    function doChangeColorOfRow(evenTR, oddTR) {
    $(evenTR).each(function() {
      $(this).css("background-color", "#F0F8FF").bind("mouseover", function() {
        if ($(this).css("background-color") != "#ffff00") {
          $(this).css("background-color", "#D8FAD8");
        }
      }).bind("mouseout", function() {
        if ($(this).css("background-color") != "#ffff00") {
          $(this).css("background-color", "#F0F8FF");
        }
      }).bind("click", function() {
        $(evenTR).each(function() {
          if ($(this).css("background-color") == "#ffff00") {
            $(this).css("background-color", "#F0F8FF");
          }
        });
        $(oddTR).each(function() {
          if ($(this).css("background-color") == "#ffff00") {
            $(this).css("background-color", "#ffffff");
          }
        });
        $(this).css("background-color", "#ffff00");
      });
    });
    $(oddTR).each(function() {
      $(this).css("background-color", "#ffffff").bind("mouseover", function() {
        if ($(this).css("background-color") != "#ffff00") {
          $(this).css("background-color", "#D8FAD8");
        }
      }).bind("mouseout", function() {
        if ($(this).css("background-color") != "#ffff00") {
          $(this).css("background-color", "#ffffff");
        }
      }).bind("click", function() {
        $(evenTR).each(function() {
          if ($(this).css("background-color") == "#ffff00") {
            $(this).css("background-color", "#F0F8FF");
          }
        });
        $(oddTR).each(function() {
          if ($(this).css("background-color") == "#ffff00") {
            $(this).css("background-color", "#ffffff");
          }
        });
        $(this).css("background-color", "#ffff00");
      });
    });
  }
  </script>
</head>
<body>
  <form id="form1" runat="server">
  <table  cellpadding="0" cellspacing="0" id="tableThis">
    <tr id="header">
      <td>納稅人</td>
      <td>
        &nbsp;
        增值稅</td>
      <td>
        &nbsp;
        消費稅</td>
      <td>
        &nbsp;
        營業(yè)稅</td>
        <td>小規(guī)模納稅人</td>
        <td>增值稅小規(guī)模納稅人</td>
    </tr>
    <tr>
    <td class="style2">張三</td>
      <td class="style1">
        123423432.12</td>
      <td class="style1">
        &nbsp;
        32445345.13</td>
      <td class="style1">
        &nbsp;
        345564.25</td>
              <td class="style1">567657567.78</td>
        <td class="style1">3454353453.90</td>
    </tr>
    <tr>
    <td class="style2">李四</td>
      <td class="style1">
        &nbsp;
        34435345.34</td>
      <td class="style1">
        &nbsp;
        456546</td>
      <td class="style1">
        &nbsp;
        675675</td>
              <td class="style1">678879789</td>
        <td class="style1">34534534.0</td>
    </tr>
     <tr>
    <td class="style2">王五</td>
      <td class="style1">
        &nbsp;
        23424</td>
      <td class="style1">
        &nbsp;
        6546</td>
      <td class="style1">
        &nbsp;
        67868</td>
              <td class="style1">980890</td>
        <td class="style1">45345</td>
    </tr>
     <tr>
    <td class="style2">劉六</td>
      <td class="style1">
        &nbsp;
        234234</td>
      <td class="style1">
        &nbsp;
        123123</td>
      <td class="style1">
        &nbsp;
        324234</td>
              <td class="style1">342423</td>
        <td class="style1">345345</td>
    </tr>
     <tr>
    <td class="style2">趙七</td>
      <td class="style1">
        &nbsp;
        345345</td>
      <td class="style1">
        &nbsp;
        546546</td>
      <td class="style1">
        &nbsp;
        567567</td>
              <td class="style1">67867867</td>
        <td class="style1">67867</td>
    </tr>
     <tr>
    <td class="style2">王八</td>
      <td class="style1">
        &nbsp;
        345354</td>
      <td class="style1">
        &nbsp;
        345345</td>
      <td class="style1">
        &nbsp;
        5654</td>
              <td class="style1">567658678</td>
        <td class="style1">879879789</td>
    </tr>
     <tr>
    <td class="style2">李九</td>
      <td class="style1">
        &nbsp;
        34535</td>
      <td class="style1">
        &nbsp;
        4534</td>
      <td class="style1">
        &nbsp;
        756765</td>
              <td class="style1">867867</td>
        <td class="style1">897987987</td>
    </tr>
     <tr>
    <td class="style2">周十</td>
      <td class="style1">
        &nbsp;
        456434534</td>
      <td class="style1">
        546456&nbsp;
      </td>
      <td class="style1">
        &nbsp;
        5675756</td>
              <td class="style1">67867867</td>
        <td class="style1">8797987</td>
    </tr>
     </table>
  </form>
</body>
</html>

更多關于jQuery相關內(nèi)容感興趣的讀者可查看本站專題:《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結》、《jQuery擴展技巧總結》、《jQuery常用插件及用法總結》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結》

希望本文所述對大家jQuery程序設計有所幫助。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI