载入中
自定义HTML载入中... loading
object.execCommand [原创 2006-05-29 19:03:43]  删除... 
字体变小 字体变大
这个东东在在线的可视化编辑器中经常用到。(注意:只是IE支持)
 
语法
bSuccess = object.execCommand(sCommand [, bUserInterface] [, vValue]);
 
参数的意义
sCommand:必选参数,字符串型. 这是要执行的方法名. 可以是任意可以在脚本语言里面执行的命令。(命令见附录)
bUserInterface 可选项.布尔型. 默认为false. 不执行用户接口. 
                     为true时,如sCommand 支持用户接口,执行之.
vValue 可选项.可以是字符串,数字或其它值。选什么值,依赖于sCommand。
 
返值
如果命令执行成功,返回 true,否则false
 
注意
1、如果页面没有调入完成,请不要使用此方法。
2、bUserInterface和vValue在command运行时也许会被用到
例子
这个例子使用了CreateLink作为execCommand的sCommand参数,允许用户用超级链接替换所选择的文字。
<HTML>
<BODY>
<H1 unselectable="on">创建超连接并重定向 URL</H1>
<script>
function AddLink()
{//Identify selected text
var sText = document.selection.createRange();
if (!sText==""){
    //创建链接
     document.execCommand("CreateLink");
     //用超连接替换所选文字
     if (sText.parentElement().tagName == "A"){
       sText.parentElement().innerText=sText.parentElement().href;
       document.execCommand("ForeColor","false","#FF0033");
     }   
  }
else{
    alert("请选择蓝色文字!");
  }  
}
</script>
<P unselectable="on">选择下面的文字,并且单击“添加链接”,输入网址,网址会被替换.</P>
<P style="color=#3366CC">我的最喜欢的网址很值得一看哦!</P>
<BUTTON onclick="AddLink()" unselectable="on">添加链接</BUTTON>
</BODY>
</HTML> 
 
 
************************************************************************
2D-Position

Allows absolutely positioned elements to be moved by dragging.

AbsolutePosition

Sets an element's position property to "absolute."

BackColor

Sets or retrieves the background color of the current selection.

BlockDirLTR

Not currently supported.

BlockDirRTL

Not currently supported.

Bold

Toggles the current selection between bold and nonbold.

BrowseMode

Not currently supported.

ClearAuthenticationCache

Clears all authentication credentials from the cache. Applies only to execCommand.

Copy

Copies the current selection to the clipboard.

CreateBookmark

Creates a bookmark anchor or retrieves the name of a bookmark anchor for the current selection or insertion point.

CreateLink

Inserts a hyperlink on the current selection, or displays a dialog box enabling the user to specify a URL to insert as a hyperlink on the current selection.

Cut

Copies the current selection to the clipboard and then deletes it.

Delete

Deletes the current selection.

DirLTR

Not currently supported.

DirRTL

Not currently supported.

EditMode

Not currently supported.

FontName

Sets or retrieves the font for the current selection.

FontSize

Sets or retrieves the font size for the current selection.

ForeColor

Sets or retrieves the foreground (text) color of the current selection.

FormatBlock

Sets the current block format tag.

Indent

Increases the indent of the selected text by one indentation increment.

InlineDirLTR

Not currently supported.

InlineDirRTL

Not currently supported.

InsertButton

Overwrites a button control on the text selection.

InsertFieldset

Overwrites a box on the text selection.

InsertHorizontalRule

Overwrites a horizontal line on the text selection.

InsertIFrame

Overwrites an inline frame on the text selection.

InsertImage

Overwrites an image on the text selection.

InsertInputButton

Overwrites a button control on the text selection.

InsertInputCheckbox

Overwrites a check box control on the text selection.

InsertInputFileUpload

Overwrites a file upload control on the text selection.

InsertInputHidden

Inserts a hidden control on the text selection.

InsertInputImage

Overwrites an image control on the text selection.

InsertInputPassword

Overwrites a password control on the text selection.

InsertInputRadio

Overwrites a radio control on the text selection.

InsertInputReset

Overwrites a reset control on the text selection.

InsertInputSubmit

Overwrites a submit control on the text selection.

InsertInputText

Overwrites a text control on the text selection.

InsertMarquee

Overwrites an empty marquee on the text selection.

InsertOrderedList

Toggles the text selection between an ordered list and a normal format block.

InsertParagraph

Overwrites a line break on the text selection.

InsertSelectDropdown

Overwrites a drop-down selection control on the text selection.

InsertSelectListbox

Overwrites a list box selection control on the text selection.

InsertTextArea

Overwrites a multiline text input control on the text selection.

InsertUnorderedList

Toggles the text selection between an ordered list and a normal format block.

Italic

Toggles the current selection between italic and nonitalic.

JustifyCenter

Centers the format block in which the current selection is located.

JustifyFull

Not currently supported.

JustifyLeft

Left-justifies the format block in which the current selection is located.

JustifyNone

Not currently supported.

JustifyRight

Right-justifies the format block in which the current selection is located.

LiveResize

Causes the MSHTML Editor to update an element's appearance continuously during a resizing or moving operation, rather than updating only at the completion of the move or resize.

MultipleSelection

Allows for the selection of more than one site selectable element at a time when the user holds down the SHIFT or CTRL keys.

Open

Not currently supported.

Outdent

Decreases by one increment the indentation of the format block in which the current selection is located.

OverWrite

Toggles the text-entry mode between insert and overwrite.

Paste

Overwrites the contents of the clipboard on the current selection.

PlayImage

Not currently supported.

Print

Opens the print dialog box so the user can print the current page.

Redo

Not currently supported.

Refresh

Refreshes the current document.

RemoveFormat

Removes the formatting tags from the current selection.

RemoveParaFormat

Not currently supported.

SaveAs

Saves the current Web page to a file.

SelectAll

Selects the entire document.

SizeToControl

Not currently supported.

SizeToControlHeight

Not currently supported.

SizeToControlWidth

Not currently supported.

Stop

Not currently supported.

StopImage

Not currently supported.

StrikeThrough

Not currently supported.

Subscript

Not currently supported.

Superscript

Not currently supported.

UnBookmark

Removes any bookmark from the current selection.

Underline

Toggles the current selection between underlined and not underlined.

Undo

Not currently supported.

Unlink

Removes any hyperlink from the current selection.

Unselect

Clears the current selection.

票数:
什么是“我顶”?
点击数:    评论数:
本文章引用通告地址(TrackBack Ping URL)为:
本文章尚未被引用。
下一篇: 真的热了
发表评论
大 名:
(不填写则显示为匿名者)
网 址:
(您的网址,可以不填)
标 题:
内 容:
请根据下图中的字符输入验证码:
(您的评论将有可能审核后才能发表)
和讯个人门户 v1.0 | 和讯部落 | 客服中心