| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1151 人关注过本帖
标题:一个页面多次用到同一个javascript函数的问题?
只看楼主 加入收藏
fuhuijun
Rank: 1
等 级:新手上路
帖 子:407
专家分:0
注 册:2007-10-30
结帖率:80%
收藏
 问题点数:0 回复次数:7 
一个页面多次用到同一个javascript函数的问题?
问一下大家就是我现在要在一个页面多次用到同一个javascript函数,可不可以啊,现在就是'公告','新品','促消'和'行业培训','免费讲座','厂商培训','相关信息',两个模块的功能是一样的,都是用的同一个javascript函数,我测试的时候是他们不在同一个页面的时候可以正常显示,但是放到同一个页面就不能正常显示了,下面是我的javascript函数:
<script type="text/javascript">
function nTabs(thisObj,Num){
if(thisObj.className == "active")return;
var tabObj = thisObj.parentNode.id;
var tabList = document.getElementById(tabObj).getElementsByTagName("li");
for(i=0; i <tabList.length; i++)
{
  if (i == Num)
  {
   thisObj.className = "active";
      document.getElementById(tabObj+"_Content"+i).style.display = "block";
  }else{
   tabList[i].className = "normal";
   document.getElementById(tabObj+"_Content"+i).style.display = "none";
  }
}
}
</script>
这是我要在页面上显示的
<link href="css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function nTabs(thisObj,Num){
if(thisObj.className == "active")return;
var tabObj = thisObj.parentNode.id;
var tabList = document.getElementById(tabObj).getElementsByTagName("li");
for(i=0; i <tabList.length; i++)
{
  if (i == Num)
  {
   thisObj.className = "active";
      document.getElementById(tabObj+"_Content"+i).style.display = "block";
  }else{
   tabList[i].className = "normal";
   document.getElementById(tabObj+"_Content"+i).style.display = "none";
  }
}
}
</script>
<table id="__01" width="787" height="1824" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <img src="images/index4_03_03_01.jpg" width="780" height="72" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_02.jpg" width="780" height="2" alt=""></td>
    </tr>
    <tr>
        <td width="787" height="26">
            <table id="__01" width="780" height="26" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td>
            <img src="images/index4_03_03_03_01.jpg" width="40" height="26" alt=""></td>
        <td width="740" height="26" valign="middle" background="images/index4_03_03_03_02.jpg"><a href="#"><span class="cc">色谱|</span></a>&nbsp;<a href="#"><span class="cc">光谱|</span></a>&nbsp;<a href="#"><span class="cc">质谱&nbsp;|</span></a>&nbsp;<a href="#"><span class="cc">元素分析&nbsp;|</span></a>&nbsp;<a href="#"><span class="cc">电化学&nbsp;|</span></a>&nbsp;<a href="#"><span class="cc">显微镜&nbsp;|</span></a>&nbsp;<a href="#"><span class="cc">表面分析&nbsp;|</span></a>&nbsp;<a href="#"><span class="cc">粒度仪&nbsp;|</span></a>&nbsp;<a href="#"><span class="cc">热分析&nbsp;|</span></a>&nbsp;<a href="#"><span class="cc">试验机&nbsp;|</span></a>&nbsp;<a href="#"><span class="cc">物理光学仪器&nbsp;|</span></a>&nbsp;<a  href="#"><span class="cc">生化仪器&nbsp;|</span></a><a href="#"><span class="cc">环保仪器</span></a></td>
    </tr>
</table>
      </td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_04.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td width="787" height="265" valign="top">
        <table id="__01" width="775" height="265" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="775" height="265" valign="top">
        <table width="780" height="265" border="0">
  <tr>
    <td width="522"><table width="522" height="264" border="0" cellspacing="1" bgcolor="#6E92AC">
      <tr>
        <td width="522" height="16" valign="top" background="images/index4_03_03_05_01_01.jpg" bgcolor="#FFFFFF"></td>
      </tr>
      <tr>
        <td bgcolor="#FFFFFF" valign="top"></td>
      </tr>
    </table></td>
    <td width="255" valign="top"><table width="255" height="264" border="0">
      <tr>
        <td width="242" height="215" valign="top" align="left"><div align="center">

  <!-- 选项卡1开始 -->
  <div class="nTab" style=width:249px>
    <!-- 标题开始 -->
    <div class="TabTitle">
      <ul id="myTab1">
        <li class="active" onclick="nTabs(this,0);">公告</li>
        <li class="normal" onclick="nTabs(this,1);">新品</li>
        <li class="normal" onclick="nTabs(this,2);">促消</li>
      
      </ul>
    </div>
    <!-- 内容开始 -->
    <div class="TabContent">
      <div id="myTab1_Content0"> 000 </div>
      <div id="myTab1_Content1" class="none"> 111 </div>
      <div id="myTab1_Content2" class="none"> 222 </div>
    </div>
  </div>
  <!-- 选项卡1结束 -->
</div></td>
      </tr>
      <tr>
        <td height="43" valign="top"><img src="images/index4_03_03_05_03_04.jpg" width="249" height="43"></td>
      </tr>
    </table></td>
  </tr>
</table>

        
</td>
  </tr>
</table>
        
        
      </td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_06.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_07.jpg" width="780" height="69" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_08.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td width="780" height="227" valign="top">table id="__01" width="780" height="227" border="0" cellpadding="0" cellspacing="0">
    <tr>
        <td width="522" height="227"><div align="center">

  <!-- 选项卡1开始 -->
  <div class="ntab" style=width:520px>
    <!-- 标题开始 -->
    <div class="ntabtitle">
      <ul id="myTab1">
       <li class="active" onclick="ntabs(this,0);">行业培训</li>
        <li class="normal" onclick="ntabs(this,1);">免费讲座</li>
        <li class="normal" onclick="ntabs(this,2);">厂商培训</li>
        <li class="normal" onclick="nntabs(this,3);">相关信息</li>
      
      </ul>
    </div>
    <!-- 内容开始 -->
    <div class="ntabcontent">
      <div id="myTab1_Content0"> 行业培训 </div>
      <div id="myTab1_Content1" class="none"> 免费讲座 </div>
      <div id="myTab1_Content2" class="none"> 厂商培训 </div>
      <div id="myTab1_Content3" class="none">相关信息</div>
    </div>
  </div>
  <!-- 选项卡1结束 -->
</div>
      </td>
        <td width="2" height="227">        </td>
        <td width="255" height="227" valign="top"><table width="255" height="227" border="0" cellspacing="1" bgcolor="#6E92AC">
          <tr>
            <td height="15" background="images/index4_03_03_09_03.jpg" bgcolor="#FFFFFF">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#"><span class="gd">更多&gt;&gt;</span></a></td>
          </tr>
          <tr>
            <td bgcolor="#FFFFFF">&nbsp;</td>
          </tr>
        </table></td>
    </tr>
</table>
</td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_10.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_11.jpg" width="780" height="68" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_12.jpg" width="780" height="4" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_13.jpg" width="780" height="231" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_14.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_15.jpg" width="780" height="68" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_16.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_17.jpg" width="780" height="218" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_18.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_19.jpg" width="780" height="71" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_20.jpg" width="780" height="4" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_21.jpg" width="780" height="203" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_22.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_23.jpg" width="780" height="69" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_24.jpg" width="780" height="3" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/index4_03_03_25.jpg" width="780" height="200" alt=""></td>
    </tr>
</table>

[[italic] 本帖最后由 fuhuijun 于 2008-1-22 16:33 编辑 [/italic]]

未命名.jpg (39.97 KB)
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: javascript 函数 页面 
2008-01-22 16:23
fuhuijun
Rank: 1
等 级:新手上路
帖 子:407
专家分:0
注 册:2007-10-30
收藏
得分:0 
下边是我的页面,有点看不清楚,大家可以点进去看一下
2008-01-22 16:26
fuhuijun
Rank: 1
等 级:新手上路
帖 子:407
专家分:0
注 册:2007-10-30
收藏
得分:0 
小弟在线等待大家的回答,谢谢
2008-01-22 16:27
lmhllr
Rank: 8Rank: 8
等 级:贵宾
威 望:44
帖 子:1504
专家分:42
注 册:2005-5-12
收藏
得分:0 
代码太长而且不完整......实在没办法看下去了。...

但可以肯定的是:一个函数在一个页面可以用任意多次,我估计你这里的ID重复了.....
2008-01-22 16:53
wyg4859
Rank: 2
等 级:新手上路
威 望:4
帖 子:883
专家分:0
注 册:2006-8-2
收藏
得分:0 
代码太长,看得头疼,考虑一下回答者的感受!谢谢

http://www.找到组织!找到党!
2008-01-22 16:58
fuhuijun
Rank: 1
等 级:新手上路
帖 子:407
专家分:0
注 册:2007-10-30
收藏
得分:0 
如果是id 重复的话,该怎么解决啊,谢谢了啊,我对javascript不是很了解,谢谢了
2008-01-22 18:21
zhulei1978
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
收藏
得分:0 
<!-- 选项卡1开始 -->
  <div class="ntab" style=width:520px>
    <!-- 标题开始 -->
    <div class="ntabtitle">
      <ul id="myTab2">
       <li class="active" onclick="nTabs(this,0);">行业培训</li>
        <li class="normal" onclick="nTabs(this,1);">免费讲座</li>
        <li class="normal" onclick="nTabs(this,2);">厂商培训</li>
        <li class="normal" onclick="nTabs(this,3);">相关信息</li>
      
      </ul>
    </div>
    <!-- 内容开始 -->
    <div class="ntabcontent">
      <div id="myTab2_Content0"> 行业培训 </div>
      <div id="myTab2_Content1" class="none"> 免费讲座 </div>
      <div id="myTab2_Content2" class="none"> 厂商培训 </div>
      <div id="myTab2_Content3" class="none">相关信息</div>    </div>
  </div>
  <!-- 选项卡1结束 -->
</div>

[[italic] 本帖最后由 zhulei1978 于 2008-1-22 19:06 编辑 [/italic]]

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2008-01-22 19:03
fuhuijun
Rank: 1
等 级:新手上路
帖 子:407
专家分:0
注 册:2007-10-30
收藏
得分:0 
问题 解决
谢谢
2008-01-23 12:58
快速回复:一个页面多次用到同一个javascript函数的问题?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040439 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved