作成したばかりの div にアクションを追加しようとしていますが、エラーが発生しました。Chrome でインスペクターを使用しようとしたところ、ブラウザーが"$(ndiv2).click(function(){ this.dispose() });"
適切に動作することがわかりました。エラーはマウス クリック アクションで発生します。
function gMessageBox(){
this.id=new Date().getTime();
this.boxId="div"+this.id;
this.boxTextId="txt"+this.id;
this.obj=null;
}
gMessageBox.prototype = {
show: function(message){
if(document.getElementById("div_messageshow")==null){
var _body = parent.document.getElementsByTagName('body') [0];
var ndiv=document.createElement("div");//Container
var nspan=document.createElement("span")
nspan.setAttribute("id", this.boxTextId );
nspan.innerHTML=message;
ndiv.setAttribute("id", this.boxId );
var ndiv2=document.createElement("div");//close
ndiv2.innerHTML="Close";
ndiv2.setAttribute("style","float: right;cursor:pointer;");
$(ndiv2).click(function(){ this.dispose() });
ndiv.appendChild(nspan);
ndiv.appendChild(ndiv2);
_body.appendChild(ndiv);
this.obj=ndiv;
}
},
dispose: function(){
alert("dispose");
//do sth
}
};
var mb=new gMessageBox();
mb.show("im message box");