求一个JS 的简易编辑控件,能最基本的功能就行,比如 可以调节字体大小,加个超链接就可以。类型CSDN发帖,回帖这种也可以,可以不要代码功能
邮箱:[email protected]
邮箱:[email protected]
解决方案 »
- js中match()正则表达式的疑问
- jquery ImageFlow插件问题
- 下拉列表中option onclick
- 提问关于tooltip的问题。
- 不耻下问之如何在网页上通过设置一按钮来去掉什么地址栏菜单栏按钮栏收藏栏等,纯高手进ING,谢谢拉
- 请问关于两个窗口间数据传递的问题
- 用JS判断上传文件的类型的问题
- 急!!!!!!!!!如何判断一个窗口是否处于当前所有窗口的最前面????
- 能不能打开首页时检测客户端的IE版本,如是5.0和5.5指向1.HTM,如是6.0以上指向2.HTM
- javascript和css高手请进(100分相送)
- jquery不起作用,头疼
- 求类似于淘宝搜索选项卡的弹出窗口插件。
http://www.kindsoft.net/
这个我看过,功能比较强大,不好改,不知谁能提供个简易的,兼容IE,FF的???
用 document.execCommand 设置样式
//指定前景色
document.execCommand('ForeColor',false,'#BBDDCC');//true或false都可以
//指定背景色
document.execCommand('FontSize',false,7); //true或false都可以
//字体必须是系统支持的字体
document.execCommand('FontName',false,'标楷体'); //true或false都可以
//字体变粗
document.execCommand('Bold');
//变斜体
document.execCommand('Italic');//将选中的文字加下划线
document.execCommand('Underline');
//在选中的文字上划粗线
document.execCommand('StrikeThrough');
//将选中的部分文字变细
document.execCommand('SuperScript');
//将选中区块的下划线取消掉
document.execCommand('Underline');
<!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 runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选择咨询单位</title>
<style type="text/css">
</style>
</head>
<body>
<div class='divAll' style="width:1000px;">
<div class='divTop'>
<div class='top_logo'>
</div>
<div class='top_right'>
</div>
</div>
<div style="width:1000px;height:420px;">
<div id='divCenter' class='divCenter' style="width:400px; height:400px; background-color:Blue;float:left; border:1px solid red;">
<iframe id="SendMsg" name="SendMsg" width="100%" height="100%" scrolling='auto' frameborder="0" src='about:blank'></iframe>
</div>
<div id='divContent' class='divCenter' style="width:400px; height:400px;float:left; border:1px solid red;">
</div>
</div>
<div class='divBottom' style="width:1000px;">
<div class='bottom_left'>
</div>
<div id='div_bottom_center' class='bottom_center'>
<a href="#" onclick="goChat('1')">aaa</a>
<a href="javascript:void(0);" onclick="insertImg('http://www.baidu.com/search/img/logo.gif')">插入图片</a>
<a href="javascript:void(0);" onclick="insertImg('http://www.baidu.com/search/img/logo.gif',117,38)">插入图片并设置大小</a>
<a href="javascript:void(0);" onclick="insertImg('http://www.baidu.com/search/img/logo.gif',117,38,'http://www.baidu.com/search/img/logo.gif')">插入图片并添加连接</a>
<a href="javascript:void(0);" onclick="setHtml()">设置html</a>
</div>
<div class='bottom_right'>
</div>
</div>
</div>
</body><script type="text/javascript">var IframeSendMsg;
window.onload=function()
{
var s=[];
s.push('<!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>');
if(document.frames && document.documentMode){s.push('<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>');}
s.push('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><style type="text/css">html,body{font-size:15px;padding:2px;margin:0px;background-color:#FFF;word-wrap:break-word;word-break:break-all;overflow:auto;');
if(document.frames)
{
s.push('height:auto;width:96%;');
}else{
s.push('height:95%;width:auto;');
}
s.push('} p{margin:0px;padding:0px;} img{border:0px;}</style></head><body></body></html>');
if(document.frames)
{
IframeSendMsg = document.frames('SendMsg');
IframeSendMsg.document.contentEditable='true';
}
else
{
IframeSendMsg =$('SendMsg').contentWindow;
}
IframeSendMsg.document.designMode = 'On';
IframeSendMsg.document.open();
IframeSendMsg.document.writeln(s.join(''));
IframeSendMsg.document.close();
bindEvent(IframeSendMsg.document,'keydown',HotKeyDown);
IframeSendMsg.focus();
};
///键盘事件
function HotKeyDown(ev)
{
ev = ev || window.event;
if(ev==null)return false;
if( ev.ctrlKey && ev.keyCode==13)
{
alert("");
}
return true;
}
function goChat(a){
window.location.href="http://www.baidu.com";
return false;
}
// 绑定事件
function bindEvent(obj,evt,fun)
{
if(window.addEventListener){
obj.addEventListener(evt, function(e){ fun(e);},false);
}else{
obj.attachEvent('on'+evt,fun);
}
};
var $ = function (id,obj) {
return 'string' == typeof(id) ? (obj||document).getElementById(id) : id;
};
var $C = function(name,obj){
return 'string' == typeof(name) ? (obj||document).createElement(name):name;
};
function insertImg(url,w,h,linkUrl)
{
w=w||0;
h=h||0;
linkUrl=linkUrl||'';
IframeSendMsg.focus();
var range;
if(IframeSendMsg.getSelection){
range=IframeSendMsg.getSelection().getRangeAt(0);
}else if(window.document.selection){
range=IframeSendMsg.document.selection.createRange();
}
var doc = IframeSendMsg.document || window.document;
if(range.pasteHTML)
{
var s=[];
if(linkUrl!=''){
s.push('<a href=\''+linkUrl+'\' target=_blank>');
}
s.push('<img src=\''+url+'\'');
if(w>0 && h>0){
s.push(' width=\''+w+'px\' height=\''+h+'px\'');
}
s.push('/>');
if(linkUrl!=''){ s.push('</a>');}
range.pasteHTML(s.join(''));
}else if(range)
{
if(linkUrl!='')
{
var a = $C('a',doc);
a.href=linkUrl;
a.target='_blank';
var img = $C('img',doc);
img.src=url ;
if(w>0 && h>0)
{
img.style.width = w+"px";
img.style.height= h+"px";
}
range.surroundContents(a);
a.appendChild(img);
}else{
var img = $C('img',doc);
img.src=url ;
if(w>0 && h>0)
{
img.style.width = w+"px";
img.style.height= h+"px";
}
range.surroundContents(img);
}
}
}
function setHtml(){
$("divContent").innerHTML=IframeSendMsg.document.body.innerHTML;
}
</script></html>