gpt4 book ai didi

javascript - 为什么我不能在更改 src 的同时更改 HTML 属性?

转载 作者:行者123 更新时间:2023-11-28 15:08:03 25 4
gpt4 key购买 nike

我有一个带有 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" />

它有效!

关于javascript - 为什么我不能在更改 src 的同时更改 HTML 属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38032350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com