老是说typeurl没定义,明明没问题,受不了

解决方案 »

  1.   


    <script>
    window.onload=function(){
    var mytypeurl=mytype.getElementsByTagName("a");
    for(j=0;j<mytypeurl.length;j++){
    var typeurl=mytypeurl[j].name;
    mytypeurl[j].onclick = function(){
    clickstyle(typeurl);
    };
    }
    }
    function clickstyle(std)
    {
    alert(std)
    }
    </script>
    <div class="type" id="mytype">
    <div class="type_menu"><ul><li style="border-left:1px solid #bebebe;"><a href="javascript:void(0);" name="manage_goods.asp?act=1" id="selected">首页是不是</a></li><li><a href="javascript:void(0);" name="manage_goods.asp?act=2" >首页是不是</a></li></ul></div>
    </div>
      

  2.   

    mytypeurl[j].onclick=new Function("clickstyle(typeurl)");
      

  3.   

    我开始那个还有闭包问题,得到的都是一样的,用这个就好了...
    <script>
    window.onload=function(){
    var mytypeurl=mytype.getElementsByTagName("a");
    for(j=0;j<mytypeurl.length;j++){
    (function(typeurl){
    mytypeurl[j].onclick = function(){
    clickstyle(typeurl);
    }
    })(mytypeurl[j].name)
    }
    }
    function clickstyle(std)
    {
    alert(std)
    }
    </script>
    <div class="type" id="mytype">
    <div class="type_menu"><ul><li style="border-left:1px solid #bebebe;"><a href="javascript:void(0);" name="manage_goods.asp?act=1" id="selected">首页是不是</a></li><li><a href="javascript:void(0);" name="manage_goods.asp?act=2" >首页是不是</a></li></ul></div>
    </div>