我有三个js文件都要使用addLoad Event函数,但是只有最后一个js文件才能加载成功,前面两个好像给覆盖了,怎么调试都不行,请问这是哪一步错了啊,求大神解答。以下是源码:
充实文档的内容
What is the Document Object Model?
The W3C defines
the DOM as:
A platform- and language-neutral interface that will allow
programs and srcipts to dyamically access and update the content, structure and style of documents.
It is an Api
that can be uesd to navigate HTML and XML documents.
以下是addLoadEvent函数:
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
}else{
window.onload = function() {
oldonload;
func();
}
}
}
再放其中一个要加载的js文件吧
function displayCitations() {
// 取得所有引用
if (!document.getElementsByTagName || !document.createElement || !document.createTextNode) return false;
var quotes = document.getElementsByTagName("blockquote");
for (var i = 0; i < quotes.length; i++) {
if (!quotes[i].getAttribute("cite")) continue;
var url = quotes[i].getAttribute("cite");
var quoteChildren = quotes[i].getElementsByTagName("*");
if (quoteChildren.length < 1) continue;
var elem = quoteChildren[quoteChildren.length - 1];
// 创建a元素节点
var link = document.createElement("a");
// 创建值为“source”的文本节点
var link_text = document.createTextNode("source");
// 把文本节点插入a元素节点
link.appendChild(link_text);
// 把href属性节点添加给新链接
link.setAttribute("href", url);
// 创建sup属性节点
var superscript = document.createElement("sup");
// 把新链接放入sup元素
superscript.appendChild(link);
elem.appendChild(superscript);
};
}
addLoadEvent(displayCitations);
function displayAccessKeys() {
if (!document.getElementsByTagName || !document.createElement || !document.createTextNode) return false;
// 取得文档中所有的链接
var links = document.getElementsByTagName('a');
// 创建一个数组,保存访问键
var akeys = new Array();
// 遍历链接
for (var i = 0; i < links.length; i++) {
var current_link = links[i];
// 如果没有 current_link属性,继续循环
if (!current_link.getAttribute("accesskey")) continue;
// 取得accesskey的值
var key = current_link.getAttribute("accesskey");
// 取得链接文本
var text = current_link.lastChild.nodeValue;
// 添加到数组
akeys[key] = text;
}
// 创建列表
var list = document.createElement("ul");
// 遍历访问键
for (key in akeys) {
var text = akeys[key];
// 创建放到列表中的字符串
var str = key + ":" + text;
// 创建列表项
var item = document.createElement("li");
var item_text = document.createTextNode(str);
item.appendChild(item_text);
// 把列表项添加到列表中
list.appendChild(item);
}
// 创建标题
var header = document.createElement("h3");
var header_text = document.createTextNode("Accesskeys");
header.appendChild(header_text);
// 把标题添加到页面主体
document.body.appendChild(header);
// 把列表添加到页面主体
document.body.appendChild(list);
}
addLoadEvent(displayAccessKeys);
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
window.onload是只在所有js加载完后才会触发的事件回调,所以只有在你的最后一个文件加载后才会执行
同样遇到这个问题求高手解答
我也是这个问题!!我用Chrome看了提示我:elem.appendChild(superscript);这一行代码错误