| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 893 人关注过本帖
标题:问大家一个关于javascript的问题?
只看楼主 加入收藏
fuhuijun
Rank: 1
等 级:新手上路
帖 子:407
专家分:0
注 册:2007-10-30
结帖率:80%
收藏
 问题点数:0 回复次数:3 
问大家一个关于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> <a href="#"><span class="cc">光谱|</span></a> <a href="#"><span class="cc">质谱 |</span></a> <a href="#"><span class="cc">元素分析 |</span></a> <a href="#"><span class="cc">电化学 |</span></a> <a href="#"><span class="cc">显微镜 |</span></a> <a href="#"><span class="cc">表面分析 |</span></a> <a href="#"><span class="cc">粒度仪 |</span></a> <a href="#"><span class="cc">热分析 |</span></a> <a href="#"><span class="cc">试验机 |</span></a> <a href="#"><span class="cc">物理光学仪器 |</span></a> <a  href="#"><span class="cc">生化仪器 |</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">                         <a href="#"><span class="gd">更多&gt;&gt;</span></a></td>
          </tr>
          <tr>
            <td bgcolor="#FFFFFF"> </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>

未命名.jpg (39.97 KB)
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: javascript thisObj 函数 var 
2008-01-22 16:47
icelovebai
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-9-19
收藏
得分:0 
”我测试的时候是他们不在同一个页面的时候可以正常显示,但是放到同一个页面就不能正常显示了“
不明白你什么意思~
2008-01-22 19:23
fuhuijun
Rank: 1
等 级:新手上路
帖 子:407
专家分:0
注 册:2007-10-30
收藏
得分:0 
问题解决了
谢谢
id 重复了
2008-01-23 12:29
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
id不一样会出现找不到HTML对象的错误
2008-01-24 14:04
快速回复:问大家一个关于javascript的问题?
数据加载中...
 
   



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

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