查出输出目录树菜单的内容。以后颜色部分为自写的,但我输出的不知道是啥,输啥,输出的感觉不对,请求高手指正。 <script> 
function encode(keywords){ 
  return keywords.replace(/&/g,"&amp;").replace(/ </g,"&lt;").replace(/>/g,"&gt;").replace(/([\\\.\*\[\]\(\)\$\^])/g,"\\$1"); 

function vk(keywords){ 
  if (keywords.length==0){ 
    alert('please enter keywords'); 
    return false; 
  } 
keywords=encode(keywords); 
var tree1 = document.getElementsByTagName("ul")[0].childNodes; 
for (var i = 0;i < tree1.length;i++){ 
if(keywords=tree1[i]){ 
document.write(tree1[i].innerHTML); 


document.write(" <br> <br> <strong>取内层ul的li信息: </strong> <br>"); 
var tree2 = document.getElementsByTagName("ul")[1].childNodes; 
for (var i = 0;i < tree2.length;i++){ 
if(keywords=tree2[i]){ 
document.write(tree2[i].innerHTML); 



</script>   
<style type="text/css"> 
.highlight{background:green;font-weight:bold;color:white;} 
</style> <base href="http://javascript.internet.com/navigation/"> 
<script type="text/javascript" src="http://javascript.internet.com/navigation/scripts.js"> 
</script> 
<style type="text/css"> 
#containerul .symbols{ 
  float:left; 
  width:12px; 
  height:1em; 
  background-position:0 50%; 
  background-repeat:no-repeat; 

</style> 
<form onsubmit="vk(this.keywords.value);"> 
  <p> 
    <input name="keywords" id="keywords" title="go"/> 
    <input name="submit" type="submit" value="Go"/> 
    <input name="reset" type="reset" value="Clear"/> 
  </p> 
</form> <ul id="containerul" > 
  <li> 
    <strong>SuperPro Programmers </strong> 
    <ul> 
      <li>Hardware Related </li> 
  <ul> 
    <li>Is it possible to store the project data on the CF card in a MS FAT32 file format so that it 
can be read and written with CF card reader? 
        <ul> 
<li>The project data can't be read out using a CF card reader. CF card on SP3K works as a 
data memory instead of a file diskette. The programmer reads project data from CF card 
directly and then programs the device. Data security is another concern for such 
solution. The project includes 3 files, *.prj,*.dcf, and *.erp. If you want to send the 
project files to the vendor, you can send the projects that you saved in your computer or 
send the CF card with saved/downloaded project files in it.        
        </ul> 
        </li> 
        <li>I got the error message” cannot found programmer” when I installed Xeltek 9000U on my 
computer. 
<ul> 
<li>A minimum of one CF card must be inserted in the programmer before turning on the 
programmer. If you are using one CF card, insert the card into the slot of module 1. 
Having no CF cards installed into the programmer may result in a communication error 
when turning on the software. The CF cards are used as memory storage for each 
module, this a module without a CF card is disabled. 
Please check the details in the Xeltek 9000U manual. </lil> 
</ul> 
    </li> 
  </ul> 
      <li>Installation Troubleshooting </li> 
  <ul> 
    <li>Is it possible to store the project data on the CF card in a MS FAT32 file format so that it 
can be read and written with CF card reader? 
        <ul> 
<li>The project data can't be read out using a CF card reader. CF card on SP3K works as a 
data memory instead of a file diskette. The programmer reads project data from CF card 
directly and then programs the device. Data security is another concern for such 
solution. The project includes 3 files, *.prj,*.dcf, and *.erp. If you want to send the 
project files to the vendor, you can send the projects that you saved in your computer or 
send the CF card with saved/downloaded project files in it.        
        </ul> 
        </li> 
        <li>I got the error message” cannot found programmer” when I installed Xeltek 9000U on my 
computer. 
<ul> 
<li>A minimum of one CF card must be inserted in the programmer before turning on the 
programmer. If you are using one CF card, insert the card into the slot of module 1. 
Having no CF cards installed into the programmer may result in a communication error 
when turning on the software. The CF cards are used as memory storage for each 
module, this a module without a CF card is disabled. 
Please check the details in the Xeltek 9000U manual. </lil> 
</ul> 
    </li> 
  </ul> 
      <li> 
        Programmer Guide/Tip </li> 
    </ul> 
  </li> 
  <li> 
    <strong>SuperPro Software    </strong> 
    <ul> 
      <li> 
        Accessify      </li> 
      <li> 
        World Wide Web Consortium 
        <ul> 
          <li> 
            The W3C Markup Validator          </li> 
  <ul> 
          <li> 
            The W3C CSS Validator          </li> 
  </ul> 
          <li> 
            The Web Content Accessibility Guidelines          </li> 
        </ul> 
      </li> 
    </ul> 
  </li> 
</ul> 
</div> 
<script type="text/javascript"> 
initiate(); // This must be placed immediately after the menu in order to format it properly. 
</script> </BODY> 
</HTML>

解决方案 »

  1.   

    查出输出目录树菜单的内容。以后颜色部分为自写的,但我输出的不知道是啥,输啥,输出的感觉不对,请求高手指正。 <script> 
    function encode(keywords){ 
      return keywords.replace(/&/g,"&amp;").replace(/ </g,"&lt;").replace(/>/g,"&gt;").replace(/([\\\.\*\[\]\(\)\$\^])/g,"\\$1"); 

    function vk(keywords){ 
      if (keywords.length==0){ 
        alert('please enter keywords'); 
        return false; 
      } 
    keywords=encode(keywords); 
    var tree1 = document.getElementsByTagName("ul")[0].childNodes; 
    for (var i = 0;i < tree1.length;i++){ 
    if(keywords=tree1[i]){ 
    document.write(tree1[i].innerHTML); 


    document.write(" <br> <br> <strong>取内层ul的li信息: </strong> <br>"); 
    var tree2 = document.getElementsByTagName("ul")[1].childNodes; 
    for (var i = 0;i < tree2.length;i++){ 
    if(keywords=tree2[i]){ 
    document.write(tree2[i].innerHTML); 



    </script>  
    <style type="text/css"> 
    .highlight{background:green;font-weight:bold;color:white;} 
    </style> <base href="http://javascript.internet.com/navigation/"> 
    <script type="text/javascript" src="http://javascript.internet.com/navigation/scripts.js"> 
    </script> 
    <style type="text/css"> 
    #containerul .symbols{ 
      float:left; 
      width:12px; 
      height:1em; 
      background-position:0 50%; 
      background-repeat:no-repeat; 

    </style> 
    <form onsubmit="vk(this.keywords.value);"> 
      <p> 
        <input name="keywords" id="keywords" title="go"/> 
        <input name="submit" type="submit" value="Go"/> 
        <input name="reset" type="reset" value="Clear"/> 
      </p> 
    </form> <ul id="containerul" > 
      <li> 
        <strong>SuperPro Programmers </strong> 
        <ul> 
          <li>Hardware Related </li> 
      <ul> 
        <li>Is it possible to store the project data on the CF card in a MS FAT32 file format so that it 
    can be read and written with CF card reader? 
            <ul> 
    <li>The project data can't be read out using a CF card reader. CF card on SP3K works as a 
    data memory instead of a file diskette. The programmer reads project data from CF card 
    directly and then programs the device. Data security is another concern for such 
    solution. The project includes 3 files, *.prj,*.dcf, and *.erp. If you want to send the 
    project files to the vendor, you can send the projects that you saved in your computer or 
    send the CF card with saved/downloaded project files in it.        
            </ul> 
            </li> 
            <li>I got the error message” cannot found programmer” when I installed Xeltek 9000U on my 
    computer. 
    <ul> 
    <li>A minimum of one CF card must be inserted in the programmer before turning on the 
    programmer. If you are using one CF card, insert the card into the slot of module 1. 
    Having no CF cards installed into the programmer may result in a communication error 
    when turning on the software. The CF cards are used as memory storage for each 
    module, this a module without a CF card is disabled. 
    Please check the details in the Xeltek 9000U manual. </lil> 
    </ul> 
        </li> 
      </ul> 
          <li>Installation Troubleshooting </li> 
      <ul> 
        <li>Is it possible to store the project data on the CF card in a MS FAT32 file format so that it 
    can be read and written with CF card reader? 
            <ul> 
    <li>The project data can't be read out using a CF card reader. CF card on SP3K works as a 
    data memory instead of a file diskette. The programmer reads project data from CF card 
    directly and then programs the device. Data security is another concern for such 
    solution. The project includes 3 files, *.prj,*.dcf, and *.erp. If you want to send the 
    project files to the vendor, you can send the projects that you saved in your computer or 
    send the CF card with saved/downloaded project files in it.        
            </ul> 
            </li> 
            <li>I got the error message” cannot found programmer” when I installed Xeltek 9000U on my 
    computer. 
    <ul> 
    <li>A minimum of one CF card must be inserted in the programmer before turning on the 
    programmer. If you are using one CF card, insert the card into the slot of module 1. 
    Having no CF cards installed into the programmer may result in a communication error 
    when turning on the software. The CF cards are used as memory storage for each 
    module, this a module without a CF card is disabled. 
    Please check the details in the Xeltek 9000U manual. </lil> 
    </ul> 
        </li> 
      </ul> 
          <li> 
            Programmer Guide/Tip </li> 
        </ul> 
      </li> 
      <li> 
        <strong>SuperPro Software    </strong> 
        <ul> 
          <li> 
            Accessify      </li> 
          <li> 
            World Wide Web Consortium 
            <ul> 
              <li> 
                The W3C Markup Validator          </li> 
      <ul> 
              <li> 
                The W3C CSS Validator          </li> 
      </ul> 
              <li> 
                The Web Content Accessibility Guidelines          </li> 
            </ul> 
          </li> 
        </ul> 
      </li> 
    </ul> 
    </div> 
    <script type="text/javascript"> 
    initiate(); // This must be placed immediately after the menu in order to format it properly. 
    </script> </BODY> 
    </HTML>
      

  2.   

    要实现什么效果?
    if(keywords=tree1[i]) 比较要用两个等号,==,
    关键字和节点比较,有何意义?
    document.write <---会把文档的内容冲掉的
      

  3.   

    那么多代码一般不会有人有耐心看下去的,你试试JQuery框架吧,吧所有<ul>下的<li>输出就是:$("ul>li").html()
      

  4.   

    不是很清楚,看意思好像是取和关键字相同的UL里面的LI的名字
      

  5.   

    可以用htmlparser解析,很方便!