【編輯器開發】基本js指令
來源:互聯網
上載者:User
最近在研究編輯器的開發,這方面的東西網上的例子比較少,因為大家都在用免費的編輯器,或別人開發好的,這種編輯器大多都是用js寫的,今天在網上找了一篇比較全的execCommand事件的重載方法,全轉過來供以後查詢。
ID.document.designMode="on" 使iframe處在可編輯狀態為off時為不可以編輯
ID.focus(); 擷取當前iframe的焦點
ID.document.selection.createRange(); 擷取文字框中選中區內容
ID.document.execCommand(s); 在當前文檔、選中區或給定範圍上執行命令
execCommand參數
ID.document.execCommand('Cut'); 剪下
ID.document.execCommand('Copy') 拷貝
ID.document.execCommand('Paste') 粘貼
ID.document.execCommand('Undo') 撤消
ID.document.execCommand('Redo') 重做
ID.document.execCommand('Delete') 刪除
ID.document.execCommand('Bold') 黑體
ID.document.execCommand('Italic') 斜體
ID.document.execCommand('Underline') 底線
ID.document.execCommand('StrikeThrough'); 在選中的文字上劃粗線
ID.document.execCommand('SuperScript'); 將選中的部分文字變細
ID.document.execCommand('Underline'); 將選中區塊的底線取消掉
ID.document.execCommand('stop') 停止
ID.document.execCommand('SaveAs') 儲存
ID.document.execCommand('Saveas',false,'c:\\test.htm') 另存新檔
ID.document.execCommand('FontName',false,'標楷體') 字型字型必須是系統支援的字型true或false都可以
ID.document.execCommand('FontSize',false,fs) 字型大小
ID.document.execCommand('refresh',false,0) 重新整理
ID.document.execCommand('CreateLink',true,'true') 彈出一個對話方塊輸入URL建立一個超連結
ID.document.execCommand('CreateLink',false,'http://www.51js.com') 建立一個超連結
ID.document.execCommand('BackColor',true,'#FFbbDD') 將選中的區塊設為指定的背景色true或false都可以
ID.document.execCommand('ForeColor',false,'#BBDDCC') 指定前景色彩true或false都可以
ID.document.execCommand('FontSize',false,7) 指定背景色true或false都可以
ID.document.execCommand('InsertOrderedList') 有序列排列
ID.document.execCommand('InsertUnorderedList') 實心無序列排列
ID.document.execCommand('Indent') 空心無序列排列
ID.document.execCommand('Delete') 刪除選中的區塊
ID.document.execCommand('Cut') 剪下選中的區塊
表單類
ID.document.execCommand('InsertButton',false,"aa") 新增加一個Button true或false無效 document.all.aa.value="風舞九天"
ID.document.execCommand('InsertInputButtong',false,"aa") 新增加一個input true或false無效 document.all.aa.value="風舞九天"
ID.document.execCommand('InsertFieldSet',true,"aa") 重設為一個fieldset document.all.aa.innerText="刀劍如夢"
ID.document.execCommand('InsertHorizontalRule',true,"aa") 插入一個水平線
ID.document.execCommand('InsertIFrame',true,"aa") 插入一個iframe
ID.document.execCommand('InsertImage',false,"aa") 插入一個InsertImage,設為true時需要圖片,false時不需圖片
ID.document.execCommand('InsertInputCheckbox',true,"aa") 插入一個checkbox
ID.document.execCommand('InsertInputFileUpload',false,"aa") 插入一個file類型的object
ID.document.execCommand('InsertInputHidden',false,"aa") 插入一個hidden
ID.document.execCommand('InsertInputImage',false,"aa") 插入一個InputImage document.all.aa.src="F-a10.gif";
ID.document.execCommand('InsertInputPassword',true,"aa") 插入一個Password
ID.document.execCommand('InsertInputRadio',false,"aa") 插入一個Radio
ID.document.execCommand('InsertInputReset',true,"aa") 插入一個Reset
ID.document.execCommand('InsertInputSubmit',false,"aa") 插入一個Submit
ID.document.execCommand('InsertInputText',false,"aa") 插入一個input text
ID.document.execCommand('InsertTextArea',true,"aa") 插入一個textarea
ID.document.execCommand('InsertSelectListbox',false,"aa") 插入一個 select list box
ID.document.execCommand('InsertSelectDropdown',true,"aa") 插入一個single select
ID.document.execCommand('InsertParagraph') 插入一個line break(硬斷行符號??)
ID.document.execCommand('InsertMarquee',true,"aa") 插入一個marquee document.all.aa.innerText="bbbbb"
ID.document.execCommand('Unselect') 於取消選中的陰影部分
ID.document.execCommand('SelectAll') 選中頁面上的所有元素
ID.document.execCommand('SaveAs','mycodes.txt'); 第二個參數為欲儲存的檔案名稱
ID.document.execCommand('print') 列印整個頁面
ID.document.execCommand("SuperScript") 上標
ID.document.execCommand("SubScript") 下標
ID.document.execCommand("Outdent") 向前縮排
ID.document.execCommand("Indent") 向後縮排
ID.document.execCommand("JustifyLeft") 居左
ID.document.execCommand("JustifyRight") 居右
ID.document.execCommand("JustifyCenter") 置中
ID.document.execCommand("ForeColor","",CColor) 字型顏色
在焦點位置上插入html
ID.focus(); //擷取當前iframe的焦點
o = ID.document.selection.createRange();//擷取文字框中選中區內容
o.pasteHTML("<img src=\"\" width=\"100\" height=\"100\">")