movi
小狐狸
小狐狸
  • UID25900
  • 注册日期2008-08-20
  • 最后登录2009-09-28
  • 发帖数4
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:1876回复:3

请问下大家这个js代码应该怎么改写才能firefox下有效

楼主#
更多 发布于:2008-08-20 02:48
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" ;
}
bigflybird
火狐狸
火狐狸
  • UID23032
  • 注册日期2008-02-24
  • 最后登录2011-08-01
  • 发帖数283
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
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)"
movi
小狐狸
小狐狸
  • UID25900
  • 注册日期2008-08-20
  • 最后登录2009-09-28
  • 发帖数4
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
2楼#
发布于:2008-08-20 02:48
测试有效。
这里果然有高手,
谢谢!
eilern
狐狸大王
狐狸大王
  • UID22371
  • 注册日期2007-12-20
  • 最后登录2017-10-13
  • 发帖数468
  • 经验10枚
  • 威望1点
  • 贡献值20点
  • 好评度13点
  • 社区居民
3楼#
发布于:2008-08-20 02:48
啊喏,这段代码是干啥的?
游客

返回顶部