Js uses cookies to refresh the unchanged tree menu and cookie tree
You can set the cookie to save the status of the tree menu and re-read the cookie when loading the page to set the menu.
The HTML structure of the menu:
<Div class = "treemenu"> <ul> <li> <a href = "#" id = "treemenu_a_1"> Level 1 menu </a> <div class = "submenu "id =" submenu_1 "> <ul> <li> <a href =" subpage/a.html "id =" submenu_a_1_1 "> Level 1 </a> </li> <li> <a href = "subpage/B .html" id = "submenu_a_1_2"> Level 2 menu 2 </a> </li> <a href = "#" id = "submenu_a_1_3"> Level 2 menu 3 </a> </li> <a href = "#" id = "submenu_a_1_4"> Level 2 menu 4 </a> </ li> <a href = "#" id = "submenu_a_00005"> Level 2 menu 5 </a> </li> </ul> </div> </li> <li> <a href = "#" id = "treemenu_a_2"> Level 1 menu 2 </a> <div class = "submenu" id = "submenu_2"> <ul> <li> <a href = "#" id = "submenu_a_2_1"> Level 1 menu </a> <div class = "submenu" id = "submenu_2_1"> <ul> <li> <a href = "#" id = "submenu_a_2_1_1"> Level 3 menu 1 </a> </li> <a href = "#" id = "submenu_a_2_1_2 "> Level 3 menu 2 </a> </li> <a href =" # "id =" submenu_a_2_1_3 "> Level 3 menu 3 </a> <div class = "submenu" id = "submenu_2_1_3"> <ul> <li> <a href = "#" id = "submenu_a_2_1_3_1"> Level 4 menu 1 </a> </li> <li> <a href = "#" id = "submenu_a_2_1_3_2"> Level 4 menu 2 </a> </li> <a href = "#" id = "submenu_a_2_1_3_3 "> Level 4 menu 3 </a> </li> </ul> </div> </li> <li> <a href = "#" id = "submenu_a_2_2"> Level 2 menu </a> </li> <a href = "#" id = "submenu_a_2_3"> level 2 menu 3 </a> </li> <a href = "#" id = "submenu_a_2_4"> Level 2 menu 4 </a> </li> <li> <a href = "#" id = "submenu_a_2_5"> Level 2 menu 5 </a> </li> </ul> </div> </li> <li> <a href = "#" id = "treemenu_a_3"> Level 1 menu 3 </a> <div class = "submenu" id = "submenu_3"> <ul> <li> <a href = "#" id = "submenu_a_3_1"> Level 1 </a> </li> <a href = "#" id = "submenu_a_3_2"> Level 2 menu 2 </a> </li> <a href = "#" id = "submenu_a_3_3"> Level 2 menu 3 </a> </li> <li> <a href = "#" id = "submenu_a_3_4"> Level 2 menu 4 </a> </li> <a href = "#" id = "submenu_a_3_5"> level 2 menu 5 </a> </li> </ul> </div>
Cookie reading tool:
// Cookie tool class var cookieTool ={// read cookiegetCookie: function (c_name) {if (document. cookie. length> 0) {c_start = document. cookie. indexOf (c_name + "="); if (c_start! =-1) {c_start = c_start + c_name.length + 1; c_end = document. cookie. indexOf (";", c_start); if (c_end =-1) {c_end = document. cookie. length;} return unescape (document. cookie. substring (c_start, c_end) ;}} return "" ;}, // set cookiesetCookie: function (c_name, value, expiredays) {var exdate = new Date (); exdate. setDate (exdate. getDate () + expiredays); // you can specify the date document. cookie = c_name + "=" + escape (value) + (e Xpiredays = null )? "": "; Expires =" + exdate. toGMTString () ;}, // Delete cookiedelCookie: function (c_name) {var exdate = new Date (); exdate. setDate (exdate. getDate ()-1); // yesterday's date document. cookie = c_name + "=; expires =" + exdate. toGMTString ();}};
Menu event binding:
// Menu event binding $ ('. treemenu '). bind ('click', function () {var $ this = $ (this); var id = $ this. attr ('id'); var $ submenu = $ this. next ('. submenu '); if ($ submenu. length> 0) {// whether a sub-menu is available var flag =$ (this ). next ('. submenu: Den den '). length> 0? True: false; if (flag) {$ submenu. show () ;}else {$ submenu. hide () ;}var display = flag? 'Block': 'none'; cookieTool. setCookie (id, display, 10);} else {cookieTool. setCookie (id, id, 10); var curId = cookieTool. getCookie (id); $ ('. treemenu '). find ('. on '). removeClass ('on '). addClass ('off'); $ ('#' + curId ). addClass ('on'); $ ('. treemenu a [class = "off"] '). each (function () {cookieTool. delCookie ($ (this ). attr ('id'); // delete other selected cookie });}});
Reset the menu when loading the page
// Load the page to read cookies $ ('. treemenu '). each (function () {showMenu ($ (this ). attr ('id') ;}); // read the cookie display menu function showMenu (id) {var $ this =$ ('#' + id ); var cookie = cookieTool. getCookie (id); if (cookie) {if ($ this. next ('. submenu '). length> 0) returns %this.next('.submenu'%.css ('display', cookie);} else {$ ('#' + cookie ). addClass ('on ');}}}
Complete DEMO:
Too many cript?click to refresh the unchangeable tree dish (multi-level menu bar. Zip
Note: The chrome local console cannot read cookies. You need to test them in firefox/IE or server environment.
How does one use cookies in JS to keep the current content Status unchanged after the page is refreshed?
The answer is not correct. </Title>: <meta name = "save" content = "history"> indicates the record history. Add the style = "behavior: url (# default # savehistory)" attribute to the control to record the status, indicating that the control needs to remember the status. Example: <Head>
<Title> saveHistory behavior application </title>
<Meta name = "save" content = "history">
</Head>
<Body>
<P> form items with saveHistory behavior: <br>
<INPUT style = "behavior: url (# default # savehistory)"> <br>
General Form Items: <br>
<Input>
</P>
<Form name = "form1" method = "post" style = "behavior: url (# default # savehistory)" action = "">
<Label>
<Select name = "select" id = "select">
<Option value = "1111"> 1111 </option>
<Option value = "2222"> 2222 </option>
</Select>
</Label>
</Form>
<STYLE type = text/css>
# Box3 {padding: 10px; border: 1px solid green ;}
</STYLE> <SCRIPT type = text/javascript>
Function openShutManager (oSourceObj, oTargetObj, shutAble, oOpenTip, oShutTip ){
Var sourceObj = typeof oSourceObj = "string "? Document. getElementById (oSourceObj): oSourceObj;
Var targetObj = typeof oTargetObj = "string "? Document. getElementById (oTargetObj): oTargetObj;
Var openTip = oOpenTip | "";
Var shutTip = oShutTip | "";
If (targetObj. style. display! = "None") ...... the remaining full text>
Js, JavaScript + cookie control can open a valid Web page within five minutes, otherwise all are opened prompt page, equal to anti-Refresh
1. Speed up XP boot and Shutdown
Choose Start> RUN> Regedit 〕
Find the HKEY_CURRENT_USER \ Control Panel \ Desktop key and change WaitToKillAppTimeout of the right window to 1000.
(Originally set value: 20000) that is, when the program is closed, it takes only one second.
Change the value of HungAppTimeout to 200 (original value: 5000), indicating that the program waits for 0.5 seconds when an error occurs.
Locate HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \ Control
Set the key value WaitToKillServiceTimeout to 1000 or smaller. (Original value: 20000)
Change the value of the key value HungAppTimeout to [200 〕
2. Speed up the pre-read capability and improve the boot speed
Windows XP pre-read setting can increase system speed and speed up startup.
In [start] → [run] → type [Regedit], find HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Control \ SessionManager \ MemoryManagement. In the right-side window of PrefetchParameters, change the value of [EnablePrefetcher] as follows:
If the PIII is above 800 MHz, you can try to change the numeric data to [4] or [5 〕
We recommend that you retain the numeric data as the default value ([3 〕
3. automatically close the stop Response Program upon Shutdown
Let the system automatically shut down the Response Program.
Open the HKEY_CURRENT_USER \ Control Panel \ Desktop key in the registry and set AutoEndTasks to 1. (Original value: 0)
4. Run the Defrag program when the computer is started.
Choose Start> RUN> Regedit> HKEY_LOCAL_MACHINE 〕
→ [SOFTWARE] → [Microsoft] → [Dfrg] → [BootOptimizeFunction 〕
Set the key value [Enable] to [Y] to Enable and set to [N] to disable.
5. Reduce the wait time for multiple startup
Open start \ Control Panel \ System \ Advanced \ Start and repair items \ press Settings \ system start \ default Operating System -- check both items-enter the time you want to wait ps: if you enter "0", the system will not let you wait and directly load the operating system you selected last time.
Another method
Use Notepad to open the boot. ini file in the C: \ directory and change the value of [timeout] From the preset 30 (seconds) to the required waiting time-Archive
6. Reduce the waiting time when Windows XP is started and loaded into the regional network
Open Network Connection
Right-click to view "properties" of "Local Connection"
In general, select "Internet Protocol (TCP/IP)" and press the content
If you use a fixed IP address, it will not pause after the instance is started.
7. Use Microsoft Bootvis.exe to optimize startup speed
Download the bootVis.exe file, decompress it, and run unzip bootVis.exe 〕
After [Trace] selects [next boot + driver delays] or other selected projects, XP restarts and records the startup data to generate a BIN file.
Open the file in 〔bootvis.exe → [file] → [open] → go to [Trace] → select [... full text>