阅读:1876回复:3
请问下大家这个js代码应该怎么改写才能firefox下有效
var debug = false ;
function switchTab (tab) { event.returnValue = false ; var tabName = getTabGroupName (tab.id) ; if (tabName == '') { alert ("No tabName for tab [" + tab.id + "]") ; return ; } var index = 1 ; while (true) { var tabTitle = eval ("document.getElementById ('" + tabName + '_' + index + "')") ; if (tabTitle == undefined) break ; deactiveTabTitle (tabTitle , tabName) ; var tabContent = eval ("document.getElementById ('" + tabName + '_' + index + '_content' + "')") ; if (tabContent != undefined) tabContent.style.display = "NONE" ; index ++ ; } if (debug) alert ("Find " + (index - 1) + " tab title(s) for TabName [" + tabName + "]") ; activeTabTitle (tab , tabName) ; var tabContent = eval ("document.getElementById ('" + tab.id + '_content' + "')") ; if (tabContent != undefined) tabContent.style.display = "BLOCK" ; } function cancelTab () { } function getTabGroupName (tabId) { if (tabId == '' || tabId == undefined) { alert ("tabId is NULL! [" + tabId + "]") ; return ; } var i = tabId.lastIndexOf ('_') ; if (i <= 1) return '' ; return tabId.substr (0 , i) ; } function deactiveTabTitle (tab , tabName) { tab.className = tabName + "_off" ; } function activeTabTitle (tab , tabName) { tab.className = tabName + "_on" ; } |
|
1楼#
发布于:2008-08-20 02:48
var debug = false ;
function switchTab (e, tab) { StopEvent(e) ; var tabName = getTabGroupName (tab.id) ; if (tabName == '') { alert ("No tabName for tab [" + tab.id + "]") ; return ; } var index = 1 ; while (true) { var tabTitle = eval ("document.getElementById ('" + tabName + '_' + index + "')") ; if (tabTitle == undefined) break ; deactiveTabTitle (tabTitle , tabName) ; var tabContent = eval ("document.getElementById ('" + tabName + '_' + index + '_content' + "')") ; if (tabContent != undefined) tabContent.style.display = "NONE" ; index ++ ; } if (debug) alert ("Find " + (index - 1) + " tab title(s) for TabName [" + tabName + "]") ; activeTabTitle (tab , tabName) ; var tabContent = eval ("document.getElementById ('" + tab.id + '_content' + "')") ; if (tabContent != undefined) tabContent.style.display = "BLOCK" ; } function cancelTab () { } function getTabGroupName (tabId) { if (tabId == '' || tabId == undefined) { alert ("tabId is NULL! [" + tabId + "]") ; return ; } var i = tabId.lastIndexOf ('_') ; if (i <= 1) return '' ; return tabId.substr (0 , i) ; } function deactiveTabTitle (tab , tabName) { tab.className = tabName + "_off" ; } function activeTabTitle (tab , tabName) { tab.className = tabName + "_on" ; } function StopEvent(pE) { if (!pE) if (window.event) pE = window.event; else return; if (pE.cancelBubble != null) pE.cancelBubble = true; if (pE.stopPropagation) pE.stopPropagation(); if (pE.preventDefault) pE.preventDefault(); if (window.event) pE.returnValue = false; if (pE.cancel != null) pE.cancel = true; } 调用: onclick="switchTab(event, this)" |
|
2楼#
发布于:2008-08-20 02:48
测试有效。
这里果然有高手, 谢谢! |
|
3楼#
发布于:2008-08-20 02:48
啊喏,这段代码是干啥的?
|
|