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 關注
- 126 瀏覽
添加回答
舉報