Home > Back-end >  JS switch in different types of images
JS switch in different types of images

Time:04-30

CurIndex. Img SRC="https://bbs.csdn.net/topics/images/" + + ". PNG ";//1, 2, 3
I wrote the above code, want to ask teacher, if there is a JPG image format, GIF how to add code, thank you.

CodePudding user response:

Img SRC you all already know how to assign a value, then you can change the image path behind the can ah,

CodePudding user response:

reference 1st floor rumlee response:
. Img SRC you all already know how to assign a value, then you can change the image path behind the can ah,

Is not a teacher, I have the PNG image format JPG, GIF

CodePudding user response:

CurIndex. Img SRC="https://bbs.csdn.net/topics/images/" + + ". PNG "-". PNG "is used to switch a select choices. JPG, PNG, GIF, when used according to user selected splicing suffix

CodePudding user response:

Can maintain the full path? Don't put the suffix singled out

CodePudding user response:

Var index=0;

The function changeImg () {

//1. Get the picture that you want to switch element
Var img=document. GetElementById (" img1 ");
//calculate the current which image to switch to
Var curIndex=index % 4 + 2;//0,
CurIndex. Img SRC="https://bbs.csdn.net/topics/images/" + + ". PNG ";//1, 2, 3
//after each switch, index 1
The index=index + 1;
}

The function the init () {

SetInterval (changeImg "()", 5000);
}
The original code, because I give pictures of the format of JPG GIF format, if all of the images are PNG format can switch, but showed not to come out the other format

CodePudding user response:

reference 4 floor milo _ response:
can maintain the full path? Don't put the suffix singled out
how to ah, the teacher

CodePudding user response:

reference assw123sa reply: 3/f
. Img SRC="https://bbs.csdn.net/topics/images/" + curIndex + "PNG" - ". PNG "is used to switch a select choices. The. JPG, PNG, GIF, when used according to user selected splicing suffix
how to change a code, the teacher,
  • Related