Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery在单击时获取项目的索引_Jquery_Html - Fatal编程技术网

jQuery在单击时获取项目的索引

jQuery在单击时获取项目的索引,jquery,html,Jquery,Html,当我点击PlayVideo按钮时,我想要带视频标签的“owl项目”的索引,在这种情况下应该是3!如何使用?您可以使用此行$(“.owl stage.owl item video”).closest(“.owl item”).index()在您的案例中,它将返回owl项的索引3 演示 $(“a”)。单击(功能(e){ e、 预防默认值() var index=$(“.owl stage.owl item video”).closest(“.owl item”).index(); console.



当我点击PlayVideo按钮时,我想要带视频标签的“owl项目”的索引,在这种情况下应该是3!如何使用?

您可以使用此行
$(“.owl stage.owl item video”).closest(“.owl item”).index()
在您的案例中,它将返回
owl项的索引
3

演示

$(“a”)。单击(功能(e){
e、 预防默认值()
var index=$(“.owl stage.owl item video”).closest(“.owl item”).index();
console.log(索引)
})

您可以使用此行
$(“.owl stage.owl item video”).closest(“.owl item”).index()
在您的案例中,它将返回
owl项的索引
3

演示

$(“a”)。单击(功能(e){
e、 预防默认值()
var index=$(“.owl stage.owl item video”).closest(“.owl item”).index();
console.log(索引)
})

尝试jQuery
.index()
函数

有关更多信息,请参阅

您案例的示例代码:

<a href="">Play Video</a>
提醒一下,索引是以零为基础的。所以第一个是0

更新

我看到你想点击链接,而不是点击
.owl item

在这种情况下,请使用以下代码:

   $(".owl-item").click(function(){
      var index = $(".owl-item").index(this);

       alert("Index:  "+index);
   });

尝试jQuery
.index()
函数

有关更多信息,请参阅

您案例的示例代码:

<a href="">Play Video</a>
提醒一下,索引是以零为基础的。所以第一个是0

更新

我看到你想点击链接,而不是点击
.owl item

在这种情况下,请使用以下代码:

   $(".owl-item").click(function(){
      var index = $(".owl-item").index(this);

       alert("Index:  "+index);
   });

给你一个解决方案

$('a')。单击(函数(e){
e、 预防默认值();
console.log($('video').closest('div.owl-item').index());
});

给你一个解决方案

$('a')。单击(函数(e){
e、 预防默认值();
console.log($('video').closest('div.owl-item').index());
});


进一步澄清你的问题。@Amit当你读最后一行时,它怎么不清楚?进一步澄清你的问题。@Amit当你读最后一行时,它怎么不清楚?OP想在
上获取owl项目的索引点击OP想在
上获取owl项目的索引点击播放视频时点击OP说
按钮
aka当我点击play video按钮时,OP会显示
aka the