问题
I need to write some javascript code which will loop through all jwplayers available on a page.
The jwplayer api has a function selectPlayer():
var player = jwplayer.api.selectPlayer();
But this only returns the first player on the page. I can't see a way to find them all?
回答1:
There are a few ways to do this, but the simplest would be to call "jwplayer(x)" - where x is a zero-based index relating to an Array of jwplayers on the page - as this will return the Player instance at that index.
So for JW7 / JW8 you could simply do the following:
var jwpAll = document.querySelectorAll('.jwplayer');
for(var jwpIndex=0,jwpTotal=jwpAll.length;jwpIndex<jwpTotal;jwpIndex++){
var player = jwplayer(jwpIndex);
}
来源:https://stackoverflow.com/questions/46733833/discover-multiple-jwplayers-on-a-page