Retrieves the value of the specified attribute.
dhtml语法
vAttribute = object.getAttribute(sAttrName)
Parameters
sAttrName |
Required.
Stringthat specifies the name of the persistent attribute. |
Return Value
Variant. Returns a string, number, or Boolean, defined by sAttrName. If an explicit attribute doesn't exist, an empty string is returned. If a custom attribute doesn't exist, null is returned.
Remarks
The sAttrName value is not case sensitive.
This method requires an object participating in persistence, where that object has a class name equal to the desired persistence behavior. An id is required for the userdata and savesnapshot behaviors, and is recommended for the savehistory and savefavorite behaviors.
this method overrides the dhtml getattribute method.
DHTML代码范例
This example uses the getAttribute method to retrieve an attribute on an object participating in userData persistence.
<HEAD>
<STYLE>
.userData {behavior:url(#default#userdata);}
</STYLE>
<SCRIPT>
function fnGet(){
oPersistInput.load("oDataStore");
oPersistInput.value=oPersistInput.getAttribute("sPersistAttr");
}
function fnSet(){
oPersistInput.setAttribute("sPersistAttr",oPersistInput.value);
oPersistInput.save("oDataStore");
}
function fnRem(){
oPersistInput.removeAttribute("sPersistAttr");
oPersistInput.save("oDataStore");
}
</SCRIPT>
</HEAD>
<BODY >
<INPUT type=text class=userData id=oPersistInput>
<INPUT type=button value="Get Attribute" onclick="fnGet()">
<INPUT type=button value="Set Attribute" onclick="fnSet()">
<INPUT type=button value="Remove Attribute" onclick="fnRem()">
</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.
是否符合公共标准
This method is defined in
World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 .
Applies To
更多语法参考
introduction to dhtml behaviors, introduction to persistence, removeattribute, setAttribute