Javascript不能更改html scr

时间:2019-08-02 18:18:31

标签: javascript html

因此,我创建了一个自动幻灯片放映,但是由于某种原因,我可以让js将img scr更改为数组中的图像。

kinds
<script>
			var i= 0; // starting image
			var images= []; //image array empty-array
			var time= 2000; //2 sec time interval
			
			//image list for image array
			images[0] = 'image_1.png'; //image array starting image 
			images[1] = 'image_2.png';
			images[2] = 'image_3.png';
			
			//change image function
			function changeImg(){
				document.getElementById("imagess").scr = images[i]; //changes image on html side
				
				if(i < images.length-1){ //if var i is less then the length of the array add one, length -1 because array list start with 0 and ends with 2. 
					i++;
				} else{ // if var is more the array length set it back to 0 to start the slide again
					i = 0;
				}
				
				setTimeout("changeImg()", time);// the amount of time before the function run if statment 
			}
			
			window.onload = changeImg; //when sites loads run script
		
		</script>

2 个答案:

答案 0 :(得分:1)

document.getElementById("imagess").scr

应该是

document.getElementById("imagess").src

“ src”上的拼写错误

答案 1 :(得分:0)

它是metadata-from-file而不是src。请更改您的代码:

scr