📄 attribute.htm
字号:
<html>
<script Language="JavaScript">
var theElement;
function load(){
xmlDocObject.async = false;
xmlDocObject.loadXML("<sample><singleNode>The Value</singleNode></sample>");
theElement = xmlDocObject.documentElement.firstChild;
displayAttributes();
}
function displayAttributes(){
var attributeObj = null;
var attributesColl;
var innerString = "";
attributesColl = theElement.attributes;
attributeObj = attributesColl.nextNode();
while (attributeObj != null){
innerString = innerString + attributeObj.name + " = " + attributeObj.value + "<BR>";
attributeObj = attributesColl.nextNode();
}
AttributeValues.innerHTML = innerString;
}
function setAttr(){
var attName = NewName.value;
var attValue = NewValue.value;
theElement.setAttribute(attName, attValue);
displayAttributes();
}
function deleteAttr(){
var attName = NewName.value;
theElement.removeAttribute(attName);
displayAttributes();
}
</script>
<body onLoad="load()">
<p align="center"><b>Manipulate Attributes</b></p>
<xml ID="xmlDocObject"></xml>
Attribute Values:<BR>
<div ID="AttributeValues"></div>
<p>Attribute Name:<input type="text" ID="NewName">
Value:<input type="text" ID="NewValue"></p>
<input type="button" value="Set Attribute" onClick="setAttr()">
<input type="button" value="Remove Attribute" onClick="deleteAttr()">
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -