js里的两个调用函数无法同时使用 代码如下 求大佬帮助? 5
window.onload=function(){varoDiv=document.getElementById("pictures");varoUl=document....
window.onload = function(){
var oDiv = document.getElementById("pictures");
var oUl = document.getElementById("ul1");
var speed = -3;
var oLi = document.getElementsByTagName("li");
oUl.innerHTML += oUl.innerHTML;//先把图片增加一组
oUl.style.width = oLi.length * oLi[0].offsetWidth + "px";
function move() {
if (oUl.offsetLeft < -oUl.offsetWidth / 2) {
oUl.style.left = "0";
}
oUl.style.left = oUl.offsetLeft + speed + "px";
}
var timer = setInterval(move, 30);
oDiv.onmouseover = function() {
clearInterval(timer);
};
oDiv.onmouseout = function() {
timer = setInterval(move, 30);
};
}
window.onload = function() {
var sp = document.getElementsByTagName("span");
var cons = document.querySelector(".bd").getElementsByTagName("div");
for(var i = 0; i < sp.length; i++) {
sp[i].index = i;
sp[i].onclick = function() {
for(var j = 0; j < sp.length; j++) {
sp[j].className = "";
cons[j].className = "";
}
this.className = "current";
cons[this.index].className = "show";
}
}
} 展开
var oDiv = document.getElementById("pictures");
var oUl = document.getElementById("ul1");
var speed = -3;
var oLi = document.getElementsByTagName("li");
oUl.innerHTML += oUl.innerHTML;//先把图片增加一组
oUl.style.width = oLi.length * oLi[0].offsetWidth + "px";
function move() {
if (oUl.offsetLeft < -oUl.offsetWidth / 2) {
oUl.style.left = "0";
}
oUl.style.left = oUl.offsetLeft + speed + "px";
}
var timer = setInterval(move, 30);
oDiv.onmouseover = function() {
clearInterval(timer);
};
oDiv.onmouseout = function() {
timer = setInterval(move, 30);
};
}
window.onload = function() {
var sp = document.getElementsByTagName("span");
var cons = document.querySelector(".bd").getElementsByTagName("div");
for(var i = 0; i < sp.length; i++) {
sp[i].index = i;
sp[i].onclick = function() {
for(var j = 0; j < sp.length; j++) {
sp[j].className = "";
cons[j].className = "";
}
this.className = "current";
cons[this.index].className = "show";
}
}
} 展开
展开全部
window.onload = function () {
var oDiv = document.getElementById("pictures");
var oUl = document.getElementById("ul1");
var speed = -3;
var oLi = document.getElementsByTagName("li");
oUl.innerHTML += oUl.innerHTML;//先把图片增加一组
oUl.style.width = oLi.length * oLi[0].offsetWidth + "px";
function move() {
if (oUl.offsetLeft < -oUl.offsetWidth / 2) {
oUl.style.left = "0";
}
oUl.style.left = oUl.offsetLeft + speed + "px";
}
var timer = setInterval(move, 30);
oDiv.onmouseover = function () {
clearInterval(timer);
};
oDiv.onmouseout = function () {
timer = setInterval(move, 30);
};
var sp = document.getElementsByTagName("span");
var cons = document.querySelector(".bd").getElementsByTagName("div");
for (var i = 0; i < sp.length; i++) {
sp[i].index = i;
sp[i].onclick = function () {
for (var j = 0; j < sp.length; j++) {
sp[j].className = "";
cons[j].className = "";
}
this.className = "current";
cons[this.index].className = "show";
}
}
}
请采纳
展开全部
当然不能同时使用,这属于同名函数,后面那个会覆盖前面的那个。标准的做法是用事件监听,但估计你一时半会理解不了。也可以把两个调用函数分别做成普通的函数,然后在window.onload中进行调用,比如:
function fun1(){
var oDiv = document.getElementById("pictures");
var oUl = document.getElementById("ul1");
var speed = -3;
//...其他略...
}
function fun2() {
var sp = document.getElementsByTagName("span");
var cons = document.querySelector(".bd").getElementsByTagName("div");
//...其他略...
}
window.onload=function(){ //这里统一进行调用
fun1();
fun2();
}
function fun1(){
var oDiv = document.getElementById("pictures");
var oUl = document.getElementById("ul1");
var speed = -3;
//...其他略...
}
function fun2() {
var sp = document.getElementsByTagName("span");
var cons = document.querySelector(".bd").getElementsByTagName("div");
//...其他略...
}
window.onload=function(){ //这里统一进行调用
fun1();
fun2();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询