Table odd and even row style : Table « HTML Tags « JavaScript Tutorial

Home
JavaScript Tutorial
1.Language Basics
2.Operators
3.Statement
4.Development
5.Number Data Type
6.String
7.Function
8.Global
9.Math
10.Form
11.Array
12.Date
13.Dialogs
14.Document
15.Event
16.Location
17.Navigator
18.Screen
19.Window
20.History
21.HTML Tags
22.Style
23.DOM Node
24.Drag Drop
25.Object Oriented
26.Regular Expressions
27.XML
28.GUI Components
29.Dojo toolkit
30.jQuery
31.Animation
32.MS JScript
JavaScript Tutorial » HTML Tags » Table 




Quote from:
Sams Teach Yourself JavaScript in 21 Days (Paperback)
by Jonathan A. Watt (Author), Andrew H. Watt (Author), Jinjer Simon (Author), Jonathan A Watt (Author)

# Paperback: 784 pages
# Publisher: Sams; 1st edition (April 292002)
# Language: English
# ISBN-100672322978
# ISBN-13978-0672322976
<html>
<head>
<title>My Emails</title>

<style type="text/css">
th        {background-color: #999999}
tr.odd    {background-color: #cccccc}
tr.even   {background-color: #ffffff}
th, td    {padding: 0.1em 1em}
</style>

<script language="javascript" type="text/javascript">
<!--

var emails    = new Array();

for (var i=0; i<4; i++) {
    emails[inew Array();
}

    emails[0]["From""A";
    emails[0]["Date""2007-07-31";
    emails[0]["Subject""Hi";

    emails[1]["From""Info@java2s.com";
    emails[1]["Date""2007-07-30";
    emails[1]["Subject""Welcome";

    emails[2]["From""New Examples";
    emails[2]["Date""2007-07-29";
    emails[2]["Subject""New JavaScript";

    emails[3]["From""Unwanted Spam";
    emails[3]["Date""2007-07-28";
    emails[3]["Subject""Annoying Email";

function sortByFrom(a, b)
{
     var A = a["From"].toLowerCase();
     var B = b["From"].toLowerCase();
     if (A < Breturn -1;
     if (A > Breturn  1;
     return 0;
}

function sortByDate(a, b)
{
     var A = a["Date"];
     var B = b["Date"];
     if (A < Breturn -1;
     if (A > Breturn  1;
     return 0;
}

function sortBySubject(a, b)
{
     var A = a["Subject"].toLowerCase();
     var B = b["Subject"].toLowerCase();
     if (A < Breturn -1;
     if (A > Breturn  1;
     return 0;
}

var sortCriteria = location.search.substr(1);

if (sortCriteria) {
  emails.sort(eval(sortCriteria));
}

//-->
</script>

</head>
<body>

<h1>My Emails</h1>

<table>
  <tr>
    <td><a href="?sortByFrom">From</a></td>
    <td><a href="?sortByDate">Date</a></td>
    <td><a href="?sortBySubject">Subject</a></td>
  </tr>

<script language="javascript" type="text/javascript">
<!--

for (var i=0; i<emails.length; i++) {
  document.write("  <tr class='" ((i%2)"odd""even""'>");

  document.write("    <td>" + emails[i]["From""</td>");
  document.write("    <td>" + emails[i]["Date""</td>");
  document.write("    <td>" + emails[i]["Subject""</td>");

  document.write("  </tr>");
}

//-->
</script>

</table>

</body>
</html>














21.13.Table
21.13.1.Table odd and even row style
21.13.2.Inserrt a table cell
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.