<p> The <abbr title="World Wide Web Consortium">W3C</abbr> defines the <abbr title="Document Object Model">DOM</abbr> as: </p> <blockquote cite="http://www.w3.org/DOM/"> <p> A platform- and language-neutral interface that will allow programs and scripts to dynamically access and update the content, structure and style of documents. </p> </blockquote> <p> It is an <abbr title="Application Programming Interface">API</abbr> that can be used to navigate <abbr title="HyperText Markup Language">HTML</abbr> and <abbr title="eXtensible Markup Language">XML</abbr> documents. </p>
<dl> <dt>缩略语标题/abbr.lastChild.nodeValue</dt> <dd>缩略语定义描述/abbr.getAttribute</dd> ...... </dl>
function displayAbbreviations() {
//注释1:注意这里没有对DOM方法做兼容性检查
var abbreviations = document.getElementsByTagName("abbr");
var defs = new Array();//注释2:用数组的键值对来保存abbr的title属性和文本
//loop through the abbr list
for (var i=0; i<abbreviations.length; i++) {
var current_abbr = abbrevaitons[i];
//注释3:if (current_abbr.childNodes.length < 1) continue;
var defination = current_abbr.getAttributes("title");
var key = current_abbr.lastChild.nodeValue;
defs[key] = defination;
}
var dlist = document.createElement("dl");
//loop through the defs
for (key in defs) {
var defination = defs[key];
var dtitle = document.createElement("dt");
var dtitle_text = document.createTextNode(key);
dtitle.appendChild(dtitle_text);
var ddesc = document.createElement("dd");
var ddesc_text = document.createTextNode(defination);
ddesc.appendChild(ddesc_text);
dlist.appendChild(dtitle);
dlist.appendChild(ddesc);
}
//注释4:if (dlist.childNodes.length < 1) return false;
var header = document.createElement("h2");
var header_text = document.createElement("Abbreviations");
header.appendChild(header_text);
//注释5:下面两行用到了HTML-DOM属性:document.body,也可以用DOM core的 document.getElementsByTagName("body")[0]方法;
document.body.appendChild(header);
document.body.appendChild(dlist);
}
function displayCitations() {
//兼容性检查
if (!document.getElementsByTagName || !document.createElement
|| !document.createTextNode) return false;
//获取所有的blockquote元素
var quotes = document.getElementsByTagName("blockquote");
//1 遍历blockquote元素
for (var i=0; i<quotes.length; i++) {
// 检查是否存在cite属性
if (!quotes[i].getAttribute("cite")) continue;
// 2 提取cite属性的值
var url = quotes[i].getAttribute("cite");
// 获取blockquote包含的所有元素节点,注意是元素节点,这样就把文本节点排除掉了
var quoteChildren = quotes[i].getElementsByTagName("*");
// 判断元素是否为空
if (quoteChildren.length < 1) continue;
var elem = quoteChildren[quoteChildren.length - 1];//获取最后一个元素节点
var link = document.createElement("a");//3 创建链接节点
var link_text = document.createTextNode("source");
link.appendChild(link_text);
link.setAttribute("href", url);//4 给链接节点的href属性赋值
var superscript = document.createElement("sup");
superscript.appendChild(link);
elem.appendChild(superscript);//5 追加节点到<blockquote>包含节点的末尾
}
}
<ul id="navigation"> <li><a href="index.html" accesskey="1">Home</a></li> <li><a href="search.html" accesskey="4">Search</a></li> <li><a href="contact.html" accesskey="0">Contact</a></li> </ul>
function displayAccesskeys() {
if (!document.getElementsByTagName || !document.createElement || !document.createTextNode) return false;
// get all the links in the document
var links = document.getElementsByTagName("a");
// create an array to store the accesskeys
var akeys = new Array();
// loop through the links
for (var i=0; i<links.length; i++) {
var current_link = links[i];
// if there is no accesskey attribute, continue the loop
if (current_link.getAttribute("accesskey") == null) continue;
// get the value of the accesskey
var key = current_link.getAttribute("accesskey");
// get the value of the link text
var text = current_link.lastChild.nodeValue;
// add them to the array
akeys[key] = text;
}
// create the list
var list = document.createElement("ul");
// loop through the accesskeys
for (key in akeys) {
var text = akeys[key];
// create the string to put in the list item
var str = key + " : "+text;
// create the list item
var item = document.createElement("li");
var item_text = document.createTextNode(str);
item.appendChild(item_text);
// add the list item to the list
list.appendChild(item);
}
// create a headline
var header = document.createElement("h3");
var header_text = document.createTextNode("Accesskeys");
header.appendChild(header_text);
// add the headline to the body
document.body.appendChild(header);
// add the list to the body
document.body.appendChild(list);
}
addLoadEvent(displayAccesskeys);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有