直播中
下面我給出一個簡單的例子,你可以把它存為一個html文件,直接可以運行,這個例子的功能很簡單,就是把編輯框中選定的文字變?yōu)榇煮w或斜體。其他功能你可以參照這個例子自己加上。
對了,先把這兩個圖片存下來。
file : ubb.html
<HTML>
<HEAD>
<TITLE>ubb演示</TITLE>
</HEAD>
<BODY>
<br><br>
<table width=300 cellspacing=2 cellpadding=2 border=0 bgcolor=lightgrey>
<tr>
<td id=tdBold onclick=doAction("Bold") onmousedown="DoDown(tdBold );" onmouseover = "On_Mouseover(tdBold) ;" onmouseout="On_Mouseout(tdBold);">
<img src='bold.gif' width=16 height=16 >
</td>
<td id=tdItalic onclick=doAction("Italic") onmousedown="DoDown(tdItalic);" onmouseover = "On_Mouseover(tdItalic) ;" onmouseout="On_Mouseout(tdItalic);">
<img src='italic.gif' width=16 height=16 >
</td>
<td width=268> </td>
</tr>
<tr>
<td colspan=3>
<iframe id=Editor name=Editor border=0 scroll=no width=300 height=200>
</iframe>
</td>
</tr>
</table>
</BODY>
</HTML>
<script language=javascript>
//initialize the iframe
Editor.document .designMode = "On" ;
Editor.document .open ;
Editor.document .write (" ") ;
Editor.document .close ;
Editor.focus ();
function On_Mouseover(thisTD)
{
thisTD.style .borderLeft = "1px solid buttonhighlight" ;
thisTD.style .borderRight = "1px solid buttonshadow";
thisTD.style .borderTop = "1px solid buttonhighlight";
thisTD.style .borderBottom = "1px solid buttonshadow";
}
function On_Mouseout(thisTD)
{
thisTD.style .borderLeft = "" ;
thisTD.style .borderRight = "";
thisTD.style .borderTop = "";
thisTD.style .borderBottom = "";
}
function DoDown(thisTD)
{
thisTD.style .borderLeft = "1px solid buttonshadow";
thisTD.style .borderRight = "1px solid buttonhighlight";
thisTD.style .borderTop = "1px solid buttonshadow";
thisTD.style .borderBottom = "1px solid buttonhighlight";
thisTD.style .paddingTop = "2px";
thisTD.style .paddingLeft = "2px";
thisTD.style .paddingBottom = "0px";
thisTD.style .paddingRight = "0px";
}
function doAction(str)
{
var m_objTextRange = Editor.document .selection.createRange();
m_objTextRange.execCommand(str) ;
}
</script>