我有一个带有muted
的src
视频标签。我可以以编程方式取消静音,但是如果同时更改src
(顺序无关),则无法取消静音。任何想法为什么会这样?这是一个例子:
setTimeout(function(){
// If you comment out this line and src doesn't change, it works.
$('#video').prop('src', 'http://webm.land/media/1KM9.webm');
$('#video').prop('muted', false);
}, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video id="video" autoplay muted src="http://webm.land/media/KLNV.webm" width="400" height="200" />
最佳答案
setTimeout(function() {
$('#video').removeAttr('muted');
$('#video').prop('src', 'http://webm.land/media/1KM9.webm');
document.getElementById('video').muted = false;
}, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<video id="video" autoplay muted src="http://webm.land/media/KLNV.webm" width="400" height="200" />
有用!