HBCMS更多的中文手册参考:

setData Method

DHTML文档教程

Assigns data in a specified format to the datatransfer or clipboarddata object.

dhtml语法

bsuccess = object.setdata(sdataformat, sdata)

parameters

sDataFormat Required. Stringthat specifies the format of the data to be transferred, using one of the following values:
TextTransfers data formatted as text.
URLTransfers data formatted as a URL.
sData Required. Stringthat specifies the data supplied by the source object. This information can be descriptive text, a source path to an image, or a URL for an anchor. When you pass "URL" as the sDataFormat parameter, you must use the sData parameter to provide the location of the object being transferred.

Return Value

Boolean. Returns one of the following possible values:

trueThe data was successfully added.
falseThe data was not added.

Remarks

The value of the sDataFormat parameter is not case-sensitive.

DHTML代码范例

This example uses the setData and getdata methods with the datatransfer object to create a shortcut to an image.

<HEAD>
<SCRIPT>
var sImageURL;
function InitiateDrag()
/*  The setData parameters tell the source object
to transfer data as a URL and provide the path.  */
{
event.dataTransfer.setData("URL", oImage.src);
}
function FinishDrag()
/*  The parameter passed to getData tells the target
object what data format to expect.  */
{
sImageURL = event.dataTransfer.getData("URL")
oTarget.innerText = sImageURL;
}
</SCRIPT>
</HEAD>
<BODY>
<P>This example demonstrates how to use the setData and
getData methods of the dataTransfer object to enable the
source path of the image to be dragged.</P>
<IMAGE ID=oImage SRC="../common/black.gif"
ondragstart="InitiateDrag()">
<SPAN ID=oTarget ondragenter="FinishDrag()">
Drop the image here
</SPAN>
</BODY>
This feature requires Microsoft® Internet Explorer 5 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

是否符合公共标准

There is no public standard that applies to this method.

Applies To

clipboardData, dataTransfer

更多语法参考

about dhtml data transfer, cleardata, getData