2 回答

TA贡献1951条经验 获得超3个赞
循环脚本是非常糟糕的做法。为按钮和/或视频指定一个类,并使用该类通过一段脚本来访问它 - 这意味着您甚至不需要为其提供 ID
这每次都会覆盖所有其他变量
var myVideo=document.getElementById('htmlVideo' + <?php echo $count?>);
尝试这个:
给父容器一个类:
<div class="modalClickParent col-lg-4 col-md-6 mt-3 mt-lg-5">
并使用类似的东西
$(function() {
$("[data-toggle=modal]").on("click", function() {
const myVideo = $(this).closest(".modalClickParent").next().find("video").get(0);
if (!$(this).data("playing")) {
myVideo.play();
$(this).data("playing", true);
} else {
myVideo.pause();
$(this).data("playing", false);
}
});
});

TA贡献1789条经验 获得超10个赞
只需创建一个要单击的类并为其指定 data-id 属性
在 jquery 部分使用类似的代码
$('.class').click(function(){<bR>
var that=$(this);<bR>
var id=that.data('id');<bR>
//now do your stuff here like<bR>
$('#div'+id).modal('show');<bR>
});
- 2 回答
- 0 关注
- 104 浏览
添加回答
举报