当前播放时暂停页面上的所有视频

问题描述

我在页面上有多个 html5 视频元素
当播放其中之一时,我需要暂停所有其他
这是我的尝试:

$('.player').on('play',function(){
    console.log('playing'); // this works
    $('.player').not($(this)).pause();
});

并收到控制台错误

$(...).not(...).pause is not a function

有什么帮助吗?

解决方法

.pause() 是一个 DOM 函数,而不是一个 jQuery 函数。试试:

$('.player').not($(this)).trigger('pause');