<!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>
<div id="nav"></div><script language="JavaScript" type="text/javascript">
<!--
function Obj(){
    this.name = 'lhg';
}Obj.prototype.show = function(){
    alert(this.name);
}Obj.prototype.create = function(){
    var objTemp=this
    var str = '';
    for( var i=0; i<3; i++ ){
        str += '<a href="http://www.baidu.com">'+i+'</a><br/>';
    }
    document.getElementById("nav").innerHTML = str ;
var list=document.getElementById("nav").getElementsByTagName("a")
for(var j=0;j<list.length;j++)
{
list[j].onmouseover=function(){
objTemp.show()
}
}   
}var obj1 = new Obj();
obj1.name = 'xxx';
obj1.create();
//-->
</script></body>
</html>

解决方案 »

  1.   

    1楼的写法把之前的函数覆盖了document.getElementById("nav").innerHTML = str;
    var list=document.getElementById("nav").getElementsByTagName("a");
    for(var j=0;j <list.length;j++) 

       (function(){
          var oldFun = list[j].onmouseover;
          list[j].onmouseover=function(){ 
             if(oldFun ) oldFun();  //先运行老函数
             //新的处理放在这里
          } 
       })();
      

      

  2.   

    看懂了,哈哈,原来是要设个表示this的变量呀。不过没明白2楼说的什么意思 “1楼的写法把之前的函数覆盖了 ”;
      

  3.   

    list[j].onmouseover=function(){ }
    如果list[j]己经有了onmouseover方法,那么这么写就覆盖了之前的onmouseover方法
      

  4.   

    应该不会覆盖吧,list[j]每一次都是不同的对象。