<script language="JavaScript"> 
var myTags;
myTags="标签1,标签2,标签3";
var temp
temp=myTags.split(",") 
document.write ("Tags:"); 
for(i=0;i<temp.length;i++){ 
document.write("<a href=/tags.asp?keyword="+temp[i]+">"+temp[i]+"</a> ");
}
</script>这是一段在HTML网页中的代码,目的是把上面的标签地址输出来.
请问:
能不能将这一段document.write("<a href=/tags.asp?keyword="+temp[i]+">"+temp[i]+"</a> ");
改成在script语言外面的HTML代码中,因为在JS内的话搜索引擎不能索引这些标签.

解决方案 »

  1.   

    可以。在html中加入<script>
    var myTags; 
    myTags="标签1,标签2,标签3"; 
    var temp 
    temp=myTags.split(",") 
    document.write ("Tags:"); 
    for(i=0;i <temp.length;i++){ 
    document.write(" <a href=/tags.asp?keyword="+temp[i]+">"+temp[i]+" </a> "); 

    <script>可以输出的
      

  2.   

    动态的改变<a>的href属性,行不?
      

  3.   

    行,给a一个id <a  id=test href=/tags.asp?keyword="+temp[i]+">"+temp[i]+" </a> ");
    document.getElementById("a").herf=xxx
      

  4.   

    比如<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title></title>
        <script type ="text/javascript" language ="javascript">
           var myTags; 
           myTags="标签1,标签2,标签3";
           window.onload=function(){
               var link=document.getElementById("test");
               link.innerHTML=myTags.split(",")[0];
               link.href="http://www.baidu.com"
           }
        </script>
    </head>
    <body>
    <div>Tags:<a id="test" href="">链接</a></div>
    </body>
    </html>
      

  5.   

    要实现的差不多就是这种效果,但还有一些问题:
    1. 只输出了一个链接,我希望输出的是 标签1,标签2,标签3,而且有可能会有更多的标签.
    2. 那个链接地址需要加上之前myTags.split(",")后的值.不好意思,我对JS不怎么懂.
      

  6.   


    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title></title>
        <script type ="text/javascript" language ="javascript">
           var myTags; 
           myTags="百度,雅虎,谷歌";
           var urls=["http://www.baidu.com","http://www.yaohoo.com","http://www.google.com"]
           window.onload=function(){
               addElement()
           }
           function addElement(){
             var div=document.getElementById("test");
              var tgs=myTags.split(",");
              var links='';
              for(var i=0;i<tgs.length;i++){
               links+="<a href="+urls[i]+">"+tgs[i]+"</a>   ";
              }           div.innerHTML=links;
              
           }
        </script>
    </head>
    <body>
    <div id=test></div>
    </body>
    </html>