我的页面包含此<video>
标记,其中包含多个字幕<track>
。我想通过使用jquery:
<div id="lang">
<img src="mini/ita.png" class="it" alt="Italiano" title="Italiano" />
<img src="mini/eng.png" class="en" alt="English" title="English" />
</div>
<video controls="controls" >
<source src="webcast.webm" />
<source src="webcast.mp4" />
<source src="webcast.ogv" />
<track kind="subtitles" src="./sub-en.vtt" srclang="en" />
<track kind="subtitles" src="./sub-it.vtt" srclang="it" />
</video>
<script>
$('#lang img').click(function(){
language=$(this).attr('class');
$('video track').removeAttr('default');
$('video track[srclang='+language+']').attr('default','default');
});
</script>
正确插入“default”属性,但没有替换字幕。手动插入默认属性非常有效(在chrome和opera上)。
答案 0 :(得分:0)
$('#lang img').click(function(){
language=your value;
$('#yourID').attr('srclang', language);
});
这样做..
答案 1 :(得分:0)
<script>
$('#lang img').click(function(){
var language=$(this).attr('class');
$($('video').prop('textTracks')).prop('mode', function(){
return this.language == language ? 'showing' : 'disabled';
});
});
</script>