Jquery 当我尝试循环通过视频阵列时,未定义视频阵列
我正在尝试运行一个连续循环的视频幻灯片。我已根据div id设置了数组,但收到一条错误消息,指出未定义索引。以下是html:Jquery 当我尝试循环通过视频阵列时,未定义视频阵列,jquery,html,html5-video,Jquery,Html,Html5 Video,我正在尝试运行一个连续循环的视频幻灯片。我已根据div id设置了数组,但收到一条错误消息,指出未定义索引。以下是html: <div id="div1" class="video"><video class="vidarray" src="icx.mp4"></video></div> <div id="div2" class="video"><video class="vidarray" src="icx2.mp4">&
<div id="div1" class="video"><video class="vidarray" src="icx.mp4"></video></div>
<div id="div2" class="video"><video class="vidarray" src="icx2.mp4"></video></div>
<div id="div3" class="video"><video class="vidarray" src="lastvid.mp4"></video></div>
jquery:
var videos = [
'div1',
'div2',
'div3',
]
var videos = [
['div1' , 2000],
['div2' , 2000],
['div3' , 2000],
]
// Initate a counter at 1 because you're going to show the first video by default.
var counter = 1;
setInterval(function(){
// Hide all the video divs
$(".video").hide();
// Show the video div based on the counter
$('#'+ videos[counter][0]).show();
// Reset the video to the beginning
$('video' +[counter]).load();
// Play the video
$('video' + [counter]).play();
//Increment the counter if there are still more divs to show, otherwise reset it to 0
counter == videos.length-1 ? counter = 0 : counter++;}, videos[counter][1]);
在load()上,这是jquery文档中的问题。。。索引为空
jQuery.fn.load = function( url, params, callback ) {
var selector, type, response,
self = this,
off = url.indexOf( " " );
试一试
此外,因为它们是您正在引用的ID,所以请将#放在前面:
示例-$(“#”+视频[计数器][0]).show() 哪个索引没有定义?第27行$(“#”+“视频”+[计数器]).load();上面写着第27行$(“#”+“视频”+[计数器]).load();谢谢,但是更改括号不起作用。我确实添加了“#”+,但它仍然无法识别索引。
jQuery.fn.load = function( url, params, callback ) {
var selector, type, response,
self = this,
off = url.indexOf( " " );
var videos = [
["div1", 11000],
["div2", 11000],
["div3", 2000],
]
var videos = [
{"div1", 11000},
{"div2", 11000},
{"div3", 2000},
]