我的页面有js ajax等应用 
可能 
1.动态改变<a href="somevalue"></a>的中href的值, 
2.或者是增加一个<a href="somevalue"></a>标签. 现在要求改变后的和新增加的href值都 立即作以下处理 href=funcA(hrefValue); 
请问这能用自定义事件解决吗? 

解决方案 »

  1.   

    <a  id="a1" href="somevalue"> </a>
    document.getElementById("a1").href="somevalue"
      

  2.   

    IE下有个onpropertychange事件可以用,body.appendChild没触发任何事件,
    只好用个馊主意,用setInterval轮询。
    FF下俺没辙。
    <!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>
        <title> new document </title>
        <meta name="generator" content="editplus" />
        <meta name="author" content="Gao YiXiang" />
        <meta name="email" content="[email protected]" />
        <meta name="keywords" content="javascript dhtml dom" />
        <meta name="description" content="I love web development." />
    </head>
    <body>
        <input type="hidden" id="hidACount" value="" />
        <a id="hlkUrl" href="">what is url</a><br />
        <input type="button" id="btnG" value="google" />
        <input type="button" id="btnB" value="baidu" /><br />
        <input type="button" id="btnAdd" value="Add" />
    </body>
        <script type="text/javascript">
        <!--
    function $(sId)
    {
        return document.getElementById(sId);
    }$("hlkUrl").onpropertychange  = function(){changeHref(this);};$("btnG").onclick = function()
    {
        $("hlkUrl").href = "http://www.g.cn";
    };
    $("btnB").onclick = function()
    {
        $("hlkUrl").href = "http://www.baidu.com";
    };
    $("btnAdd").onclick = function()
    {
        var a = document.createElement("a");
        a.href = "http://www.google.com";
        a.innerHTML = "google";
        document.body.appendChild(a);
    };
    document.body.onreadystatechange = function()
    {
        alert();
    };function changeHref(oLink)
    {
        if (oLink.href.indexOf("?")==-1)
        {
            oLink.href += "?from=csdn";        oLink.innerHTML = oLink.href;
        }
    }var counter = $("hidACount");
    function countHyperLink()
    {
        var c = document.getElementsByTagName("a");    if (counter.value == "")
        {
            counter.value = c.length;
        }
        else if (c.length.toString() != counter.value)
        {
            for (var i=0; i<c.length; i++)
            {
                changeHref(c[i]);
                c[i].onpropertychange = function(){changeHref(this);};
            }
        }
    }
    setInterval(countHyperLink, 500);    //-->
        </script>
    </html>
      

  3.   

    谢谢
    不过你这回方法好像不行 因为文档大 countHyperLink 要很费劲。