浏览 3796 次
锁定老帖子 主题:dwr中tabs的修改(支持记忆)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-05-24
所以就决定用这个了。 不过问题出来了。当我在tabs不是第一个中有按钮的时候,点击查询等应用,就会自动跳到第一个,非常不适用,所以决定修改 ,使用点击非第一个里面的按钮能继续在原地方 --------简单修改后的tabs.js如下---------------------- function Tabs() { } //Tabs.removeSelectedRegex = new RegExp("(^|\\s)linkSelected(\\s|$)", 'g'); //Tabs.removeUnselectedRegex = new RegExp("(^|\\s)linkUnselected(\\s|$)", 'g'); /** * */ Tabs.init = function(tabListId) { Tabs.tabLinks = document.getElementById(tabListId).getElementsByTagName("A"); var link, tabId, tab; var hasTabId="false"; var oldTabId = getTabCookie("tabId"); for (var i = 0; i < Tabs.tabLinks.length; i++) { link = Tabs.tabLinks[i]; tabId = link.getAttribute("tabId"); if (!tabId) alert("Expand link does not have a tabId element: " + link.innerHTML); tab = document.getElementById(tabId); if (!tab) alert("tabId does not exist: " + tabId); if (tabId==oldTabId) { hasTabId="true"; tab.style.display = "block"; link.className = "linkSelected " ;//+ link.className.replace(Tabs.removeUnselectedRegex, ''); } else { tab.style.display = "none"; link.className = "linkUnselected " ;//+ link.className.replace(Tabs.removeSelectedRegex, ''); } link.onclick = function() { var tabId = this.getAttribute("tabId"); setTabCookie("tabId",tabId); for (var i = 0; i < Tabs.tabLinks.length; i++) { var link = Tabs.tabLinks[i]; var loopId = link.getAttribute("tabId"); if (loopId == tabId) { document.getElementById(loopId).style.display = "block"; link.className = "linkSelected " ;//+ link.className.replace(Tabs.removeUnselectedRegex, ''); } else { document.getElementById(loopId).style.display = "none"; link.className = "linkUnselected " ;//+ link.className.replace(Tabs.removeSelectedRegex, ''); } } if (this.blur) this.blur(); return false; } } if(hasTabId=="false") { link = Tabs.tabLinks[0]; tabId = link.getAttribute("tabId"); if (!tabId) alert("Expand link does not have a tabId element: " + link.innerHTML); tab = document.getElementById(tabId); if (!tab) alert("tabId does not exist: " + tabId); tab = document.getElementById(tabId); tab.style.display = "block"; link.className = "linkSelected " ;//+ link.className.replace(Tabs.removeUnselectedRegex, ''); } } function setTabCookie(name,value) { var exp = new Date(); exp.setTime (exp.getTime()+3600000000); document.cookie = name + "=" + value + "; expires=" + exp.toGMTString(); } function getTabCookie(name) { var arg = name + "="; var alen = arg.length; var clen = document.cookie.length; var i = 0; while (i < clen) { var j = i + alen; if (document.cookie.substring(i, j) == arg) return getCookieVal (j); i = document.cookie.indexOf(" ", i) + 1; if (i == 0) break; } return null; } //cookie的相关函数 function getCookieVal (offset) { var endstr = document.cookie.indexOf (";", offset); if (endstr == -1) endstr = document.cookie.length; return unescape(document.cookie.substring(offset, endstr)); } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |