In the B/S Development era, the front-end layout of web pages also absorbed the layout of Tab pages. In particular, the combination of Ajax technology can give full play to the advantages of the good performance of Tab pages and data cache. It is a good form of webpage layout.
There are a lot of tabs on the Internet, and the implementation is similar, but the code is messy. If you want to use it, you must thoroughly understand it before you can perform secondary custom development for my use. In fact, implementing this Tab page interface is very simple. It only secretly obtains information through Ajax technology, and then displays information in turn in one area (through the display and hidden layer, or reusing a layer, fill in Html data in turn ).
The code developed by myself is the clearest and should be the best to use. If you want to expand it, your mind will not be dizzy. The Code is as follows and is being modified.
Copy codeThe Code is as follows: <! 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/5o/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> my Tabs tab (Ajax version) </title>
<Style type = "text/css">
Body {font-size: 12px ;}
# Tab0, # tab1, # tab2 {background: url (images/gray.png); cursor: hand ;}
</Style>
<Script type = "text/javascript" src = "jquery/jquery. js"> </script>
<Script type = "text/javascript" src = "class. js"> </script>
<Script type = "text/javascript" src = "my_ajax_tabs.js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function ()
{
//---------
// Tabs configuration information
Var tabs = ["# tab0", "# tab1", "# tab2"]; // tab array id
Var datas = "# div_data"; // ID of the display area object
Var event_type = "mouseover"; // trigger event (click/dblclick/mouseover/focus /...)
Var default_tab = "# tab0 ″;
// Switch the image
Var tab_selected_bgimg = "images/green.png ";
Var tab_unselected_bgimg = "images/gray.png ";
// Switch the text color
Var tab_selected_txtcolor = "# ff6600 ″;
Var tab_unselected_txtcolor = "#666666 ″;
//
Urls = [
"My_ajax_server.php? App = tab0 ″,
"My_ajax_server.php? App = tab1 ″,
"My_ajax_server.php? App = tab2 ″,
]
// ** Begin: fixed code *********************************
For (var I = 0; I <tabs. length; I ++)
{
$ (Tabs [I]). bind (event_type, handler );
}
$ (Default_tab). trigger (event_type );
//
Function handler ()
{
// Initialize the cache Array
Var localdatas = new Array (); // cache the browser's current data
For (var I = 0; I <tabs. length; I ++)
{
Localdatas [I] = ";
}
// Reset all tabs
For (var I = 0; I <tabs. length; I ++)
{
((Tabspoliciuncs.css ("background-image", "url (" + tab_unselected_bgimg + ")");
((Tabs[ I ]).css ("color", tab_unselected_txtcolor );
}
Var curr_index;
For (var I = 0; I <tabs. length; I ++)
{
If ($ (tabs [I]). attr ("id") =$ (this). attr ("id "))
{
Curr_index = parseInt (I );
}
}
//
((This).css ("background-image", "url (" + tab_selected_bgimg + ")");
((This).css ("color", tab_selected_txtcolor );
If (localdatas [curr_index] = ")
{
// Obtain data through ajax (default method = get)
$. Ajax
({
Url: urls [curr_index], // background Handler
Cache: false,
Timeout: 20000,
Error: function ()
{
Alert ("error while submitting ");
},
Success: function (data)
{
Localdatas [curr_index] = data; // cache the browser's current data
Metrics (datas).html (data );
}
});
}
Else
{// Display cached data
Metrics (datas).html (datas [curr_index]);
}
}
// ** End: fixed code *********************************
//------
});
</Script>
</Head>
<Body>
<Table border = "0" width = "500" height = "25" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td width = "97" id = "tab0"> tab0 </td>
<Td width = "30"> </td>
<Td width = "97" id = "tab1"> tab1 </td>
<Td width = "30"> </td>
<Td width = "97" id = "tab2"> tab2 </td>
<Td width = "149"> </td>
</Tr>
</Table>
<Table border = "1" width = "500" height = "60" border = "0" align = "center" cellpadding = "0" cellspacing = "0">
<Tr>
<Td>
<Div id = "div_data"> </div>
</Td>
</Tr>
</Table>
</Body>
</Html>
My_ajax_server.php file:Copy codeThe Code is as follows: <? Php
/*************************************** ****
* File: my_ajax_server.php
**************************************** ****/
Error_reporting (7 );
Set_magic_quotes_runtime (0 );
$ App = $ _ GET ['app'];
Switch ($ app)
{
Case "tab0 ″://
?>
From TAB0
<? Php
Break;
Case "tab1 ″://
?>
From TAB1
<? Php
Break;
Case "tab2 ″://
?>
From TAB2
<? Php
Break;
Default:
Echo 'my _ ajax_server.php error .';
Break;
}
?>
Zhang Qing (mesh) 9-9-18
After reading this article, refer to the next article and use jQuery technology to implement the Tab page interface II.
This article from: the foot home (www.jb51.net) detailed source reference: http://www.jb51.net/article/20091.htm