<script>function test(){
this.show = function(x){
obj[x] = this;
var i=1;
document.write('<input type=button value=test onclick="obj[\''+ x + '\'].test1(i);">');
} this.test1 = function(c){
alert(c);
alert("Hello World!");
}
}
var obj = new Object();
var x = new test();
x.show("nihao");
</script>
怎么将onclick="obj[\''+ x + '\'].test1(i)中的i传递到this.test1 = function(c) c中?
遇到瓶颈了,项目进行不下去了

解决方案 »

  1.   


    <script>function test(){
    this.show = function(x){
    obj[x] = this;
    var i=1;
    document.write('<input type="button" value="test" onclick="obj[\''+ x + '\'].test1(' + i +');">');
    }
    this.test1 = function(c){
    alert(c);
    alert("Hello World!");
    }
    }
    var obj = new Object();
    var x = new test();
    x.show("nihao");
    </script>
      

  2.   

    document.write('<input type=button value=test onclick="obj[\''+ x + '\'].test1(' + i + ');">');
      

  3.   

    ++
    就跟前面的obj的索引一样