I don't know why I don't work in the game!
$(' video) on (' play ', function () {alert (' working '); });
The $(document) on (' play ', 'video', function () {//not working});
As far as I know for audio/video, we should use get (0) to obtain the DOM but it didn't get a second, what is your guess/Suggestions?
Another approach to problems
So no one seems to know this, so I decided to use the click event, in the click event, I check if it is suspended, whether to suspend, to suspend and others play others pause this person,
The $(document) on (' click ', 'video', function () {
If ($(this). The get (0) paused)
{
$(this). The get (0). The play ();
}
The else
{
$(this). The get (0). Pause ();
}
});
In Firefox it works, but the problem in the beginning, use the chrome or Internet explorer, click on the video, it works, but when click the play button, it will not detect click event trigger. How can I solve this problem?
CodePudding user response:
You can use the following JavaScript solution to try:
Document. The getElementById (' vid1). AddEventListener (' play ', function () {alert (' working '); });
Note: "VID1" is a video element ID,
CodePudding user response:
Document. The addEventListener (' play ', function (e) {
Var video=e. arget;
If (video nodeName==='video') {
The console. The log (' onplay 'video);
//do something...
}
}, true);