在演示地址中,我对id为describe的子元素图片的尺寸进行统一赋值width="655",昨日都是正确的,今天调试过程中却失败,我的js代码地址为
window.onload = function(){
var prev = document.getElementById('prev');
var next = document.getElementById('next');
var sImg = document.getElementById('slider-img1');
var sCation = document.getElementById('slider-cation');
var arrayImg = ['http://dag1688.aliapp.com/wp-content/uploads/2015/11/dag-1.jpg','http://dag1688.aliapp.com/wp-content/uploads/2015/11/dag-2.jpg','http://dag1688.aliapp.com/wp-content/uploads/2015/11/dag-3.jpg','http://dag1688.aliapp.com/wp-content/uploads/2015/11/dag-4.jpg'];
var arrayText = ['大光五金旗舰店实拍','国际国内一线品牌代理商','30年五金机电行业服务经验','贵州省各大工矿企业优秀供应商'];
var num = 0;
document.getElementById('pIcon').onmouseover = function () {
document.getElementById('pIcon').style.color = "green";
};
document.getElementById('pIcon').onmouseout = function () {
document.getElementById('pIcon').style.color = "gray";
};
document.getElementById('nIcon').onmouseover = function () {
document.getElementById('nIcon').style.color = "green";
};
document.getElementById('nIcon').onmouseout = function () {
document.getElementById('nIcon').style.color = "gray";
};
sImg.onmouseover = function(){
sImg.style.filter = "brightness(100%)";
};
sImg.onmouseout = function(){
sImg.style.filter = "brightness(200%)";
};
//幻灯片初始化
function checkout (){
sImg.src = arrayImg[num];
sCation.innerHTML = arrayText[num];
};
checkout();
prev.onclick = function(){
num --;
if(num==-1){
num = 3;
}
checkout();
};
next.onclick = function(){
num ++;
if(num == 4){
num = 0;
}
checkout();
};
// 以下是宽度为655的图片样本格式化
var pImg = document.getElementsByClassName('describe')[0];
var img = pImg.getElementsByTagName('img');
var htmlinline = document.getElementsByClassName('htmlinline')[0].innerHTML;
for(var nu =2;nu<img.length-5;nu++){
img[nu].alt = htmlinline;
img[nu].width = "655";
}
};
最后7行为演示错误的代码,请各位大神指教
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
你的测试地址中,
获取到的DOM对象是:
木有图片啊...