FF下JS动态生成iframe编辑器,编辑状态无法启动,IE下正常,求高手解答,太奇葩了<!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=utf-8" />
<title>无标题文档</title>
<link rel="stylesheet" type="text/css" href="css/stylel.css"/>
<script>
var getTextareaByClass=function(classname){
var ifms=document.getElementsByTagName("textarea");
for(var i=0;i<ifms.length;i++){
if(ifms[i].className.indexOf(classname)>-1){
return ifms[i];
}
}
return null;
}
var extendJson=function(destination,source){
for(var json in source){
destination[json] = source[json];
}
return destination;
}var teditor=function(options){
_this = this;
_this._init(options);
_this._exec();
}
teditor.prototype={
_init:function(options){
_this.ieRange=false;
_this.options={
editor:getTextareaByClass("tEditor"),
width:0,
height:0
};
_this.options = extendJson(_this.options,options);
_this._createHTML();
},
_createHTML:function(){ //生成iframe,插入到textarea前面
var table=document.createElement("table");
table.cellSpacing = "0";
table.cellPadding = "0";
table.border = "0";
var tagsRow = table.insertRow(0);
var tagsCell = tagsRow.insertCell(0);
var iframeRow = table.insertRow(1);
var iframeCell = iframeRow.insertCell(0);

_this.editor = document.createElement("iframe");
_this.editor.style.width = !!_this.options.width ? _this.options.width : _this.options.editor.style.width;
_this.editor.style.height = !!_this.options.height ? _this.options.height : _this.options.editor.style.height;
iframeCell.appendChild(_this.editor);
_this.options.editor.parentNode.insertBefore(table,_this.options.editor);
},
_exec:function(){
                  //alert("1"); //如果在这alert延迟下后面的代码就能正常开启编辑模式
_this.win=_this.editor.contentWindow;
_this.doc=_this.win.document;
_this.doc.designMode='On';//可编辑
_this.win.focus();

}
}
window.onload=function(){
var editor=new teditor();
};
</script>
</head><body>
<textarea id="tEditor" name="tEditor" class="tEditor" style="width:600px; height:200px;"></textarea>
</body>
</html>