????
<script>
function TableDesigner(id,rowCount,colCount){
this.id=id;
this.rowCount=rowCount;
this.colCount=colCount;
}
TableDesigner.prototype.createTable=function(){
alert(this.id);
}
var td=new TableDesigner("idididi",10,10);
td.createTable();
</script>
<script>
function TableDesigner(id,rowCount,colCount){
this.id=id;
this.rowCount=rowCount;
this.colCount=colCount;
}
TableDesigner.prototype.createTable=function(){
alert(this.id);
}
var td=new TableDesigner("idididi",10,10);
td.createTable();
</script>
this.cell.attachEvent("onclick",this.onClick);this.cell.attachEvent("onclick",TableCell.prototype.onClick);//标明自己的行列号
this.rowNo=rowNo;
this.colNo=colNo;
//创建单元格元素
this.cell=document.createElement("td");
//添加响应事件
this.cell.TableCell=this;
this.cell.attachEvent("onclick",TableCellOnClick);
//添加内容
currentText = document.createTextNode("第"+this.rowNo+"行,第"+this.colNo+"列");
this.cell.appendChild(currentText);
return this.cell;
}
function TableCellOnClick(){
var tc=this.TableCell;
if("undefined"==typeof(tc.rowNo) ¦ ¦"undefined"==typeof(tc.colNo)){
alert("undefined");
return;
}
alert(tc.rowNo+":"+tc.colNo);
}
如果不行,试试改为
this.cell.onclick=TableCellOnClick;
看看情况是否一样~~~
var refThis = this;
this.cell.attachEvent("onclick", function () {refThis.onClick();});
具体的原理我不是很清楚。跟javascript的运行机制有关。