书签 分享 收藏 举报 版权申诉 / 7

类型开发iframe富文本编辑器的一点体会.docx

  • 文档编号:7368458
  • 上传时间:2023-05-11
  • 格式:DOCX
  • 页数:7
  • 大小:19.96KB



functionchangeLayout(){

varpopwin=document.getElementById('popwin');

if(!

popwin){

popwin=document.createElement('div');

popwin.id='popwin';

popwin.style.cssText='display:

none;width:

300px;height:

150px;background-color:

#ccc;position:

absolute;left:

0;top:

0px;text-align:

center;line-height:

150px;';

popwin.innerHTML='改变了layoud渲染,ie将无法撤销、重做';

document.body.appendChild(popwin);

popwin.onclick=function(){this.style.display='none'};

}

popwin.style.display=popwin.style.display=='none'?

'block':

'none';

}

functioncreateEditor(){

variframe=document.createElement('iframe');

iframe.id='iframe';

iframe.frameBorder=1;

iframe.width=400;

iframe.height=200;

document.body.appendChild(iframe);

returniframe;

}

varbind=function(element,eventType,fn,useCapture){

useCapture=useCapture||false;

if(arguments.length<3){

returntrue

};

if(window.addEventListener){

element.addEventListener(eventType,fn,useCapture);

}else{

element.attachEvent('on'+eventType,fn,useCapture);

}

}

//from司徒正美

varcss=document.defaultView?

function(el,style){

returndocument.defaultView.getComputedStyle(el,null).getPropertyValue(style)

}:

function(el,style){

style=style.replace(/\-(\w)/g,function($,$1){

return$1.toUpperCase();

});

returnel.currentStyle[style];

}

functionbindEditor(){

variframe=createEditor();

varifr_win=iframe.contentWindow;

varifr_doc=ifr_win.document;

vareditorContent='

黑体;font-weight:

bold;">阿四大四大四大

italic;text-decoration:

underline;">四大四大打算打打

italic;color:

#ff0000;">双打萨斯大师';

ifr_doc.designMode='On';//可编辑

ifr_doc.contentEditable=true;

ifr_doc.open();

ifr_doc.writeln('body{padding:

10px;margin:

0;font-size:

13px;font-family:

宋体;text-align:

left;overflow:

auto;word-wrap:

break-word;cursor:

text;background-color:

transparent;}body,p,font,div,ul,li{line-height:

1.5;}p,font,div,ul,li{line-height:

1.5;margin:

0;padding:

0}a{color:

#548DD4}'+editorContent+'');

ifr_doc.close();

vargetRange=function(){

varrange=window.getSelection?

ifr_win.getSelection():

ifr_win.document.selection;

if(!

range){

return{

node:

null,

range:

null,

text:

null

};

}

range=range.createRange?

range.createRange():

range.getRangeAt(0);

vartext=window.getSelection?

range:

range.text;

varrangeNode=null;

if(monAncestorContainer){

rangeNode=monAncestorContainer;

}else{

if(range.parentElement)rangeNode=range.parentElement();

}

return{

node:

rangeNode,

range:

range,

text:

text

}

}

varinfo=document.getElementsByTagName('span')[0];

vargetStyle=function(node){

//console.log(node)

varhtml='';

html+='

'+css(node,'font-family')+'">字体:

'+css(node,'font-family')+'
';

html+='

'+css(node,'color')+'">颜色:

'+css(node,'color')+'
';

html+='

'+css(node,'font-style')+'">斜体:

'+css(node,'font-style')+'
';

html+='

'+css(node,'font-weight')+'">粗体:

'+css(node,'font-weight')+'
';

html+='

'+css(node,'text-decoration')+'">下划线:

'+css(node,'text-decoration')+'
';

html+='tagName:

'+node.tagName+',style:

'+node.getAttribute('style')+'
';

info.innerHTML=html;

}

//当光标位置改变时候执行

varonselectionchange=function(event){

vare=event||window.event;

if(!

e.keyCode)e.keyCode=e.which;

//方向键移动光标,获取光标位置的dom

if((e.keyCode>=37&&e.keyCode<=40)||e.type=="click"){

varnode

配套讲稿:

如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。

特殊限制:

部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。

关 键  词:
开发 iframe 文本 编辑器 一点 体会
提示  冰点文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:开发iframe富文本编辑器的一点体会.docx
链接地址:https://www.bingdoc.com/p-7368458.html
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2


收起
展开