本帖最后由 yunfeifan 于 2011-11-10 16:00:52 编辑

解决方案 »

  1.   

     alert(me.value) 
    其实没看懂,猜的
      

  2.   

    me 我已经编辑,不能使用me,me是最后一个object的值。
      

  3.   


    <div style='border: 1px solid #000;width:100px; height: 100px;background: red' id="test1"></div>
    <div style='border: 1px solid #000;width:100px; height: 100px;background: green' id="test2"></div><script>
    function test(div, value){
      this.div_ = document.getElementById(div);
      this.value_ = value;
      me = this;
      this.div_.onclick = (function(){
      return function(obj){
        alert(this.id);
        alert(this.style.cssText);
      }
      })(this.div_)
    }
    window.onload = function(){
    test("test1", 1); // alert(1)
    test("test2", 2); // alert(2)
    }
    </script>
      

  4.   


    <div style='border: 1px solid #000;width:100px; height: 100px;background: red' id="test1"></div>
    <div style='border: 1px solid #000;width:100px; height: 100px;background: green' id="test2"></div><script>
    function test(div, value){
      this.div_ = document.getElementById(div);
      this.value_ = value;
      me = this;
      this.div_.onclick = (function(obj){
      return function(){
        alert(obj.id);
        alert(obj.style.cssText);
      }
      })(this.div_)
    }
    window.onload = function(){
    test("test1", 1); // alert(1)
    test("test2", 2); // alert(2)
    }
    </script>
      

  5.   

    谢谢hookee但是我并不是想要获取div_对应的内容,而是div对应的object的属性值,或许调用object的一些方法。
      

  6.   

    一样道理<div style='border: 1px solid #000;width:100px; height: 100px;background: red' id="test1"></div>
    <div style='border: 1px solid #000;width:100px; height: 100px;background: green' id="test2"></div><script>
    function test(div, value){
      this.div_ = document.getElementById(div);
      this.value_ = value;
      me = this;
      this.div_.onclick = (function(obj){
      return function(){
        alert(obj.div_.id);
        alert(obj.value_);
      }
      })(this)
    }
    window.onload = function(){
    test("test1", 1); // alert(1)
    test("test2", 2); // alert(2)
    }
    </script>
      

  7.   

    这样的?
    <body>
    <div style='border: 1px solid #000;width:100px; height: 100px;background: red' id="test1"></div>
    <div style='border: 1px solid #000;width:100px; height: 100px;background: green' id="test2"></div><script>
    function test(div, value){
      div_ = document.getElementById(div);
      div_.value_ = value;
      div_.onclick = function(evt){
      ele = window.event?window.event.srcElement:evt.target;
      alert(ele.value_)
      }
    }test("test1", 1); // alert(1)
    test("test2", 2); // alert(2)
    </script>
      

  8.   

    就是一个对象,里边有很多值,其中有一个是一个div, div有一个onclick事件,在事件内部我想获取此对象的所有的属性(或者调用此对象的一些方法),有好的办法吗?
      

  9.   

    <div style='border: 1px solid #000;width:100px; height: 100px;background: red' id="test1"></div>
    <div style='border: 1px solid #000;width:100px; height: 100px;background: green' id="test2"></div><script>
    function test(div, value){
      this.div_ = document.getElementById(div);
      this.value_ = value;
      var me = this;
      this.div_.onclick = function(){
      // alert(me.value_) 获取当前object的属性值
      }
    }test("test1", 1); // alert(1)
    test("test2", 2); // alert(2)
    </script>还是可以的