<style type="text/css"> #test1 { width: 600px; } /* 头部总体 css */ 
.ntab2-head { 
clear:both; height: 21px; 
border-bottom: #c2130e 3px solid; 
text-align: center; 
} /* 头部标头的 css */ 
.ntab2-head p { 
float:left; font-size: 14px; font-weight: bold; 
width: 80px; height: 21px; 
} /* 头部列表的 css */ 
.ntab2-head li { 
float:left; background: #dcdcdc; border-left: #f2f2f2 1px solid; 
width: 42px; cursor: pointer; font-size: 14px; 
line-height: 21px; list-style-type: none; 
} .ntab2-head li.current { 
    background: #c2130e; color: #ffffff; cursor: none; 
} /* 主体内容的 css? */ 
.ntab2-body { 
text-align: left; 
} .ntab2-body dl { 
text-indent: 0px; margin: 0px; padding: 0px; 

</style> 
<script language="javascript"> 
function ntab2_register(id, def) { 
    var obj = document.getElementById(id); 
    if (!obj || !obj.hasChildNodes()) { 
      alert('ERROR: the object was not defined for #' + id + '#'); 
      return; 
    } 
    
    // get head & body object 
    var head = null; 
    var body = null; 
    for (var i = 0; i < obj.childNodes.length; i++) { 
      var node = obj.childNodes[i]; 
      if (node.tagName == 'DIV'){ 
          if (node.className == 'ntab2-head') 
            head = node; 
          else if (node.className == 'ntab2-body') 
            body = node; 
          } 
      }
      if (!head) { alert('ERROR: head elements was not found for #' + id + '#'); return; }
      if (!body) { alert('ERROR: body elements was not found for #' + id + '#'); return; } 
    
    // set action & default 
      var items = head.getElementsByTagName('LI'); 
      var datas = body.getElementsByTagName('DL'); 
      if (items.length == 0) { alert('ERROR: empty set for head elements on #' + id + '#'); return; } 
      if (items.length != datas.length){ 
        alert('ERROR: not equal between body.length and head.length for #' + id + '#'); 
        return; 
      } 
    
      var total = items.length; 
      if (typeof def == 'undefined') def = 0; 
      else def = parseInt(def)%total; 
      if (def < 0) def += total; 
      for (var i = 0; i < total; i++) { 
        datas[i].style.display = (i == def ? '' : 'none'); 
        items[i].className = (i == def ? 'current' : '');
         
        items[i].id = i ; 
        items[i].onclick = function() { 
        
//////////////  现在这里赋值只是i ,我准备把从数据库中查询的结果通过点击不同的滑动门赋值给"hidden",请问如何编写
document.getElementById("hidden").value =this.id;
//////////////
    
            for (var k = 0; k < total; k++) { 
                datas[k].style.display = (this == items[k] ? '' : 'none'); 
                items[k].className = (this == items[k] ? 'current' : ''); 
            } 
        } 
    } 

</script> <form name="form2" method="post" action="overstock.asp"> 
<div id="test1"> 
  <!-- 头部设定 --> 
  <div class="ntab2-head"> 
    <p>新闻排行 <p> </p> 
    <li>国内 </li> 
    <li>国际 </li> 
    <li>社会 </li> 
    <li>中国 </li> 
  </div>   <!-- 内容设定 --> 
  <div class="ntab2-body"> 
    <dl> 
      国内-内容 
    </dl> 
    <dl> 
      国际-内容 
    </dl> 
    <dl> 
      社会-内容 
    </dl> 
    <dl> 
      中国 
    </dl> 
    <input type="hidden" name="hidden" id="hidden"> 
  </div> 
</div>
<hr>
<input type=button onclick="alert(document.getElementById('hidden').value) " value="test"> 
</form> 
<script language="javascript">ntab2_register('test1', 3); </script> 

解决方案 »

  1.   

    如果你的LI是从数据库查询动态生成的话,把查询的结果给相应的LI的生成一个自定义的属性
        <li mytest="11">国内 </li> 
        <li mytest="22">国际 </li> 
        <li mytest="33">社会 </li> 
        <li mytest="44">中国 </li> 
    然后使用this.mytest 调用之,赋值给你需要的就ok了。
      

  2.   

    是不是这个意思哈
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>新建网页 1</title>
    <style type="text/css"> #test1 { width: 600px; } /* 头部总体 css */ 
    .ntab2-head { 
    clear:both; height: 21px; 
    border-bottom: #c2130e 3px solid; 
    text-align: center; 
    } /* 头部标头的 css */ 
    .ntab2-head p { 
    float:left; font-size: 14px; font-weight: bold; 
    width: 80px; height: 21px; 
    } /* 头部列表的 css */ 
    .ntab2-head li { 
    float:left; background: #dcdcdc; border-left: #f2f2f2 1px solid; 
    width: 42px; cursor: pointer; font-size: 14px; 
    line-height: 21px; list-style-type: none; 
    } .ntab2-head li.current { 
        background: #c2130e; color: #ffffff; cursor: none; 
    } /* 主体内容的 css? */ 
    .ntab2-body { 
    text-align: left; 
    } .ntab2-body dl { 
    text-indent: 0px; margin: 0px; padding: 0px; 

    </style> 
    <script language="javascript"> 
    function ntab2_register(id, def) { 
        var obj = document.getElementById(id); 
        if (!obj || !obj.hasChildNodes()) { 
          alert('ERROR: the object was not defined for #' + id + '#'); 
          return; 
        } 
        
        // get head & body object 
        var head = null; 
        var body = null; 
        for (var i = 0; i < obj.childNodes.length; i++) { 
          var node = obj.childNodes[i]; 
          if (node.tagName == 'DIV'){ 
              if (node.className == 'ntab2-head') 
                head = node; 
              else if (node.className == 'ntab2-body') 
                body = node; 
              } 
          } 
          if (!head) { alert('ERROR: head elements was not found for #' + id + '#'); return; } 
          if (!body) { alert('ERROR: body elements was not found for #' + id + '#'); return; } 
        
        // set action & default 
          var items = head.getElementsByTagName('LI'); 
          var datas = body.getElementsByTagName('DL'); 
          if (items.length == 0) { alert('ERROR: empty set for head elements on #' + id + '#'); return; } 
          if (items.length != datas.length){ 
            alert('ERROR: not equal between body.length and head.length for #' + id + '#'); 
            return; 
          } 
        
          var total = items.length; 
          if (typeof def == 'undefined') def = 0; 
          else def = parseInt(def)%total; 
          if (def < 0) def += total; 
          $("hidden").value=def;
          for (var i = 0; i < total; i++) {
            datas[i].style.display = (i == def ? '' : 'none'); 
            items[i].className = (i == def ? 'current' : ''); 
            
            items[i].id = i ; 
            items[i].onclick = function() { 
            
    //////////////  现在这里赋值只是i ,我准备把从数据库中查询的结果通过点击不同的滑动门赋值给"hidden",请问如何编写 
    document.getElementById("hidden").value =this.id; 
    ////////////// 
        
                for (var k = 0; k < total; k++) { 
                    datas[k].style.display = (this == items[k] ? '' : 'none'); 
                    items[k].className = (this == items[k] ? 'current' : ''); 
                } 
            } 
        } 

    function $(id){
    return document.getElementById(id);
    }
    </script> </head><body><form name="form2" method="post" action="overstock.asp"> 
    <div id="test1"> 
      <!-- 头部设定 --> 
      <div class="ntab2-head"> 
        <p>新闻排行 <p> </p> 
        <li>国内 </li> 
        <li>国际 </li> 
        <li>社会 </li> 
        <li>中国 </li> 
      </div>   <!-- 内容设定 --> 
      <div class="ntab2-body"> 
        <dl> 
          国内-内容 
        </dl> 
        <dl> 
          国际-内容 
        </dl> 
        <dl> 
          社会-内容 
        </dl> 
        <dl> 
          中国 
        </dl> 
        <input type="hidden" name="hidden" id="hidden"> 
      </div> 
    </div> 
    <hr> 
    内容:<textarea id=ta rows=10></textarea>
    <input type=button onclick="document.getElementsByTagName('dl')[parseInt($('hidden').value)].innerText = $('ta').innerText" value="test"> 
    </form> 
    <script language="javascript">ntab2_register('test1', 3); </script>
    </body></html>