想写一个富文本编辑器,但是在执行execCommand的时候报错,请帮忙看看
代码如下<!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=gb2312">
<title>Index</title>
<script type="text/javascript">
var editor;
function InitEditor() {
editor = document.getElementById("editor");
editor = editor.contentWindow;
editor.document.designMode = "on";
setTimeout(function() {
editor.focus();
}, 10);
} function SetBold() {
document.execCommand("Blod",false,null);
} function SetItalic() {
} function SetUnderline() {
}
</script>
</head>
<body onload="InitEditor();">
<div><span><img onclick="SetBold();" src="/Images/EditorIcon/Bold.jpg" /></span>
<span><img src="/Images/EditorIcon/Italic.jpg" onclick="SetItalic();" /></span>
<span><img onclick="SetUnderline();" src="/Images/EditorIcon/Underline.jpg" /></span></div>
<iframe id="editor" src="about:blank" width="200" height="200"></iframe>
</body>
</html>再次感谢。
代码如下<!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=gb2312">
<title>Index</title>
<script type="text/javascript">
var editor;
function InitEditor() {
editor = document.getElementById("editor");
editor = editor.contentWindow;
editor.document.designMode = "on";
setTimeout(function() {
editor.focus();
}, 10);
} function SetBold() {
document.execCommand("Blod",false,null);
} function SetItalic() {
} function SetUnderline() {
}
</script>
</head>
<body onload="InitEditor();">
<div><span><img onclick="SetBold();" src="/Images/EditorIcon/Bold.jpg" /></span>
<span><img src="/Images/EditorIcon/Italic.jpg" onclick="SetItalic();" /></span>
<span><img onclick="SetUnderline();" src="/Images/EditorIcon/Underline.jpg" /></span></div>
<iframe id="editor" src="about:blank" width="200" height="200"></iframe>
</body>
</html>再次感谢。
<!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=gb2312">
<title>Index</title>
<script type="text/javascript">
var editor;
var isIE=!!document.all;
function InitEditor()
{
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(isIE && 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-family: Arial, Helvetica, sans-serif;font-size:12px;padding:2px;margin:0px;background-color:#FFF;word-break:break-all;word-wrap:break-word;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(isIE)
{
editor = frames.document.frames('editor');
editor.document.contentEditable='true';
}
else
{
editor = $('editor').contentWindow;
}
editor.document.designMode = 'On';
editor.document.open();
editor.document.writeln(s.join(''));
editor.document.close();
setTimeout(function() {
editor.focus();
}, 10);
} function SetBold() {
editor.document.execCommand("Bold",isIE,null);
} function SetItalic() {
editor.document.execCommand("Italic",isIE,null);
} function SetUnderline() {
editor.document.execCommand("Underline",isIE,null);
}
</script>
</head>
<body onload="InitEditor();">
<div><span><img onclick="SetBold();" src="/Images/EditorIcon/Bold.jpg" /></span>
<span><img src="/Images/EditorIcon/Italic.jpg" onclick="SetItalic();" /></span>
<span><img onclick="SetUnderline();" src="/Images/EditorIcon/Underline.jpg" /></span></div>
<iframe id="editor" src="about:blank" width="200" height="200"></iframe>
</body>
</html>