国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

自己動手,結合javascript和dhtml做一個ubb編輯器

2019-11-18 22:30:28
字體:
來源:轉載
供稿:網友
看到chinaasp論壇的abc code editor了嗎?是不是覺得很cool? 說真的,剛見到我還以為是用別的什么語言做的控件呢,
后來才發現沒有那么神秘的。前幾天做一個商品bbs,客戶要求支持ubb,同時也要做一個編輯器。現在我把做ubb的思路給大家講
一下。
    首先遇到的是界面問題,實際上這個很好解決,只是利用td的onmouSEOver、onmouseout和onmousedown來實現,具體實現方
法件下面的代碼。
    其次就是實現文本效果的問題,這個可以利用textRange的execCommand方法來實現。

   下面我給出一個簡單的例子,你可以把它存為一個html文件,直接可以運行,這個例子的功能很簡單,就是把編輯框中選定的
文字變為粗體或斜體。其他功能你可以參照這個例子自己加上。
對了,先把這兩個圖片存下來。

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>&nbsp;</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 ("&nbsp;") ;
  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>      


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 赤水市| 东丰县| 合作市| 科技| 连平县| 二连浩特市| 常德市| 眉山市| 衡阳县| 罗定市| 花莲县| 宁化县| 霍山县| 岐山县| 嘉定区| 运城市| 工布江达县| 莲花县| 凤山市| 平顶山市| 吉安县| 上虞市| 宣威市| 汾阳市| 凌云县| 清河县| 剑川县| 华安县| 诸暨市| 苏尼特右旗| 井冈山市| 柞水县| 许昌市| 岑巩县| 方正县| 和林格尔县| 乐昌市| 黄浦区| 曲水县| 厦门市| 龙州县|