js变量怎样加入超链接,望高手指点js变量 怎么赋值到页面的超链接望高手指点

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head><body>
    <a href="http://www.126.com/" id="demolink">无标题文档</a>
    <button onclick="foo();">click</button>
    <script type="text/javascript">
    var str="teststr";
    function foo(){
    document.getElementById('demolink').href+='?teststr';
    }
    </script>
    </body>
    </html>
      

  2.   


    <a href="#" id="link">待设置的超链接</a> document.getElementById('link').href = 'http://www.baidu.com';
      

  3.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script type="text/javascript">function btnClick() {
    var container = document.getElementById('container');
    var aLink = document.createElement('a');
    aLink.href = 'http://www.sina.com.cn';
    var textNode = document.createTextNode('新浪');
    aLink.appendChild(textNode);
    container.appendChild(aLink);
    }
    </script>
    </head>
    <body>
    <input type="button" onclick="btnClick()"></input>
    <div id="container"></div>
    </body>
    </html>这个??
      

  4.   

    谢谢各位 高手 现在 我有个 变量 right 怎样 加入 到 比如 www.baidu.com?right 这样的连接而且用 document.getElementById('link').href = 'http://www.baidu.com';只能对 一个超链接有效 我需要对多个超链接有效
      

  5.   


    function setHref(right){
     document.getElementById('link').href = 'http://www.baidu.com?right='+right;
    }
      

  6.   


    可以在这个函数里加多条语句,有几个link就加几条.. 
    :)
      

  7.   

    document.getElementById('link').href = 'http://www.baidu.com?'+right;
      

  8.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=big5" />
    <title>Untitled Document</title>
    </head><body>
    <a id="link">Baidu</a>
    </body>
    </html>
    <script>
    document.getElementById("link").onclick=function(){setHref('','','_self','link');}
    function setHref(url,param,target,el){
        if(url=='') url='http://www.baidu.com/?';
        if(url.indexOf('?')<0){
           url += '?';
        }
        url += param;
        if(el==''){
           return;
        }
        var obj = eval("document.getElementById('" + el + "')");    if(obj == null || typeof(obj)=='undefined') return;
        obj.target = target;
        obj.href = url;
    }
    </script>
      

  9.   


    function link(id){
        location.href = "login.php?id=" + id;
    }