网站后台管理系统论文,wordpress不同页面不同主题,菏泽汽车网站建设,模板网站建设哪家好之前在写叶卡切换的时候总需要把js代码写到html标签里面。 后来接触了闭包后知到一点点怎么通过闭包实现该功能。 之后又想通过cookie来记忆叶卡的当前位置。 代码如下#xff1a; !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http:/… 之前在写叶卡切换的时候总需要把js代码写到html标签里面。 后来接触了闭包后知到一点点怎么通过闭包实现该功能。 之后又想通过cookie来记忆叶卡的当前位置。 代码如下 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtdhtml xmlnshttp://www.w3.org/1999/xhtmlheadmeta http-equivContent-Type contenttext/html; charsetutf-8 /titletest/titlestyle typetext/css.cl{ clear:both;}#menu{ width:600px; height:30px;}#menu div{ display:inline;float:left; border:1px solid #000; margin-left:4px; width:80px; height:30px; line-height:30px; padding:6px;}#menu .menu_on{ background:#FFC; margin-bottom:-1px; height:31px;}#content{ border:1px solid #000; width:600px; margin-left:4px;}.c_off{ display:none;}/style/headbodydiv idmenudiv classmenu_off浙江/divdiv classmenu_off沪鲁/divdiv classmenu_off中西部/divdiv classmenu_off其他/div/divdiv idcontent classcldiv classc_off浙江/divdiv classc_off沪鲁/divdiv classc_off中西部/divdiv classc_off其他/div/divscript typetext/javascriptmyMenudocument.getElementById(menu);menuDivmyMenu.getElementsByTagName(div);myContentdocument.getElementById(content);contentDivmyContent.getElementsByTagName(div);window.onloadfunction(){ cookieId1; cookieIdgetCookie(menuId); menuDiv[cookieId].classNamemenu_on; contentDiv[cookieId].classNamec_on;for(var i0;imenuDiv.length;i) { menuDiv[i].indexi; (function(myid) { menuDiv[i].onclickfunction() {for(var i0;imenuDiv.length;i) { menuDiv[i].classNamemenu_off; contentDiv[i].classNamec_off; } this.classNamemenu_on; contentDiv[myid].classNamec_on; cookieIdthis.index; setCookie(menuId,cookieId,365); } })(i); }}function getCookie(c_name){if (document.cookie.length0){ c_startdocument.cookie.indexOf(c_name )if (c_start!-1){ c_startc_start c_name.length1 c_enddocument.cookie.indexOf(;,c_start)if (c_end-1) c_enddocument.cookie.lengthreturn unescape(document.cookie.substring(c_start,c_end))} }return }function setCookie(c_name,value,expiredays)//名称值过期时间{var exdatenew Date()exdate.setDate(exdate.getDate()expiredays)//setDate() 方法用于设置一个月的某一天。调整过的日期的毫秒表示。getDate月份中的某一天使用本地时间。返回值是 1 ~ 31 之间的一个整数。document.cookiec_name escape(value)//escape() 函数可对字符串进行编码这样就可以在所有的计算机上读取该字符串。可以使用 unescape() 对 escape() 编码的字符串进行解码。((expiredaysnull) ? : ; expiresexdate.toGMTString())//expires为过期时间。toGMTString() 方法可根据格林威治时间 (GMT) 把 Date 对象转换为字符串并返回结果。不赞成使用此方法。请使用 toUTCString() 取而代之}/script/body/html 转载于:https://www.cnblogs.com/scb1901/archive/2011/09/06/2169297.html