如何在这个JS脚本中这个图片上加链接
<divid="js_F"class="table_bk"></div><scripttype="text/javascript"><!--///*--><![CDATA...
<div id="js_F" class="table_bk"></div>
<script type="text/javascript">
<!--///*--><![CDATA[/*><!--*/
var js_F = document.getElementById("js_F");
var imgList = ["/images/dt1.gif","/images/dt2.gif","/images/dt1.gif","/images/dt2.gif",];
var imgTemp = new Array();
for (i=0; i<imgList.length; i++){
imgTemp[i] = new Image();
imgTemp[i].src = imgList[i];
}
var imgs = new Array();
var imgID = 0, nextImgID, proveImgID;
var tf = true; //图片移动方向标志
var speed1 = 10; speed2 = 5000; //速度 数值越大速度越慢
function imgInit(){
var content = '';
for (i=0; i<imgList.length; i++){
content += '<img src="' + imgList[i] + '" style="left:0;" />\n';
}
js_F.innerHTML = content;
imgs = js_F.getElementsByTagName('img');
imgs[0].style.zIndex = 20;
imgs[1].style.zIndex = 15;
}
function imgChange(){
if ((imgID+1)<imgList.length){
nextImgID = imgID + 1;
} else if (imgID<imgList.length) {
nextImgID = 0;
} else {
imgID = 0;
nextImgID = imgID + 1;
}
imgs[imgID].style.zIndex = 20;
imgs[nextImgID].style.zIndex = 15;
setTimeout('imgShow()',speed2);
}
function imgShow(){
if (tf){ //imgID向左边移动2/3,nextImgID向右边1/3
if (parseInt(imgs[imgID].style.left)>-180){
imgs[imgID].style.left = (parseInt(imgs[imgID].style.left)-10) + 'px';
imgs[nextImgID].style.left = (parseInt(imgs[nextImgID].style.left)+5) + 'px';
setTimeout('imgShow()',speed1);
} else {
tf = !tf;
imgs[imgID].style.zIndex = 15;
imgs[nextImgID].style.zIndex = 20;
setTimeout('imgShow()',speed1);
}
} else {
if (parseInt(imgs[imgID].style.left)<0){
imgs[imgID].style.left = (parseInt(imgs[imgID].style.left)+10) + 'px';
imgs[nextImgID].style.left = (parseInt(imgs[nextImgID].style.left)-5) + 'px';
setTimeout('imgShow()',speed1);
} else {
imgs[imgID].style.zIndex = 10;
tf = !tf;
imgID++;
imgChange();
}
}
}
imgInit();
imgChange();
/*]]>*///-->
</script> 展开
<script type="text/javascript">
<!--///*--><![CDATA[/*><!--*/
var js_F = document.getElementById("js_F");
var imgList = ["/images/dt1.gif","/images/dt2.gif","/images/dt1.gif","/images/dt2.gif",];
var imgTemp = new Array();
for (i=0; i<imgList.length; i++){
imgTemp[i] = new Image();
imgTemp[i].src = imgList[i];
}
var imgs = new Array();
var imgID = 0, nextImgID, proveImgID;
var tf = true; //图片移动方向标志
var speed1 = 10; speed2 = 5000; //速度 数值越大速度越慢
function imgInit(){
var content = '';
for (i=0; i<imgList.length; i++){
content += '<img src="' + imgList[i] + '" style="left:0;" />\n';
}
js_F.innerHTML = content;
imgs = js_F.getElementsByTagName('img');
imgs[0].style.zIndex = 20;
imgs[1].style.zIndex = 15;
}
function imgChange(){
if ((imgID+1)<imgList.length){
nextImgID = imgID + 1;
} else if (imgID<imgList.length) {
nextImgID = 0;
} else {
imgID = 0;
nextImgID = imgID + 1;
}
imgs[imgID].style.zIndex = 20;
imgs[nextImgID].style.zIndex = 15;
setTimeout('imgShow()',speed2);
}
function imgShow(){
if (tf){ //imgID向左边移动2/3,nextImgID向右边1/3
if (parseInt(imgs[imgID].style.left)>-180){
imgs[imgID].style.left = (parseInt(imgs[imgID].style.left)-10) + 'px';
imgs[nextImgID].style.left = (parseInt(imgs[nextImgID].style.left)+5) + 'px';
setTimeout('imgShow()',speed1);
} else {
tf = !tf;
imgs[imgID].style.zIndex = 15;
imgs[nextImgID].style.zIndex = 20;
setTimeout('imgShow()',speed1);
}
} else {
if (parseInt(imgs[imgID].style.left)<0){
imgs[imgID].style.left = (parseInt(imgs[imgID].style.left)+10) + 'px';
imgs[nextImgID].style.left = (parseInt(imgs[nextImgID].style.left)-5) + 'px';
setTimeout('imgShow()',speed1);
} else {
imgs[imgID].style.zIndex = 10;
tf = !tf;
imgID++;
imgChange();
}
}
}
imgInit();
imgChange();
/*]]>*///-->
</script> 展开
展开全部
content += '<img src="' + imgList[i] + '" style="left:0;" />\n';
改成:
content += '<a href="xxx" target="_blank"><img src="' + imgList[i] + '" style="left:0;" /></a>\n';
//xxx 可以是常量也可以是变量,自由组装
改成:
content += '<a href="xxx" target="_blank"><img src="' + imgList[i] + '" style="left:0;" /></a>\n';
//xxx 可以是常量也可以是变量,自由组装
追问
不错,但是我想加两个链接怎么加呢,一张图片一个链接这样子
追答
for (i=0; i\n';
}
没错啊,content 是在循环体中,每个图片上都有A标签啊
展开全部
function imgInit(){
var content = '';
for (i=0; i<imgList.length; i++){
content += '<img id=\"img"+i+"\" onclick=\"imgClick("+i+")\" src="' + imgList[i] + '" style="left:0;" />\n';
}
js_F.innerHTML = content;
imgs = js_F.getElementsByTagName('img');
imgs[0].style.zIndex = 20;
imgs[1].style.zIndex = 15;
}
//在此添加一个方法
function imgClick(i){
switch(i){
case 0:{
window.location.href="#";
break;
}
case 1:{
window.location.href="#";
break;
}
......
}
}
var content = '';
for (i=0; i<imgList.length; i++){
content += '<img id=\"img"+i+"\" onclick=\"imgClick("+i+")\" src="' + imgList[i] + '" style="left:0;" />\n';
}
js_F.innerHTML = content;
imgs = js_F.getElementsByTagName('img');
imgs[0].style.zIndex = 20;
imgs[1].style.zIndex = 15;
}
//在此添加一个方法
function imgClick(i){
switch(i){
case 0:{
window.location.href="#";
break;
}
case 1:{
window.location.href="#";
break;
}
......
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询