阿瑟 發表
上次介紹了如何建立Richtext輸入方塊和一個簡單的文字工具, 這次將會深入介紹execCommand方法來控制Richtext內容的輸入.
function setBold() { test.focus(); test.document.execCommand("bold"); } |
function setFont(fontSelection) { test.focus(); test.document.execCommand("FontName","",fontSelection); } |
參數名稱 | 參數 | 說明 |
FontName | 任何字型名稱 (如新細明體) |
可以改變選取文字的字型 這個指令用的是第三個參數 execCommand("ForeName","","字型名稱") |
FontSize | 從1到14的數字 | 可以改變字型的大小 這個指令用的是第三個參數 execCommand("ForeSize","", 文字大小) |
ForeColor | 任何顏色數值 (#rrggbb) |
可以改變前景(文字)的顏色 這個指令用的是第三個參數 execCommand("ForeColor","","顏色名稱") |
Bold | 沒有參數 | 將選取的文字改為粗體 |
Italic | 沒有參數 | 將選取的文字改為斜體 |
Underline | 沒有參數 | 將選取的文字加上底線 |
JustifyLeft | 沒有參數 | 將選取的文字置左 |
JustifyCenter | 沒有參數 | 將選取的文字置中 |
JustifyRight | 沒有參數 | 將選取的文字置右 |
Outdent | 沒有參數 | 減少縮排 |
Indent | 沒有參數 | 增加縮排 |
InsertOrderedlist | 沒有參數 | 設定為編號清單 |
InsertUnorderedlist | 沒有參數 | 設定為項目清單 |
CreateLink | 沒有參數 | 加入超連結 |
Cut | 沒有參數 | 剪下 |
Copy | 沒有參數 | 複製 |
Paste | 沒有參數 | 貼上 |
InsertImage | 圖片的路徑 (URL) | 可以加入圖片, 路徑可以是絕對或是相對路徑. 這個指令用的是第二個參數: execCommand("InsertImage","圖片路徑") |