gpt4 book ai didi

jquery - jquery 中的方法链音频属性

转载 作者:行者123 更新时间:2023-12-01 08:34:13 25 4
gpt4 key购买 nike

我有一个现有的函数,可以成功地将信息加载到 div 中。看起来像这样。

<div id="load_warnings">

<!-- this is where the warnings will populate from ajax request -->

</div>



<script type="text/javascript">

var auto_refresh = setInterval(
function ()
{
$('#load_warnings').load('https://www.gastromend.com/warnings.php').fadeIn("slow");
}, 20000);


</script>

问题:

我想通过在该信息加载到 div 时播放声音通知来进一步增强此功能。我正在努力理解如何在此设置中调用 jquery .play 方法。

I tried this earlier without success - No audio played.

<div id="load_warnings">

<!-- this is where the warnings will populate from ajax request -->

</div>


<script type="text/javascript">

var audioUrl = 'https://wwww.gastromend.com/resources/uploads/condodge_warning.mp3'; // declaration of audio path

var audio = new Audio(audioUrl); // instantiation of audio object

var auto_refresh = setInterval(
function ()
{
$('#load_warnings').load('https://www.gastromend.com/warnings.php').fadeIn("slow").audio.play();
}, 20000);

</script>

最佳答案

您需要告诉 audio 元素在 load() AJAX 请求完成后播放。为此,请在 load() 的回调参数中调用 play() 方法:

var audio = new Audio(audioUrl);
var auto_refresh = setInterval(function() {
var $el = $('#load_warnings').load('https://www.gastromend.com/warnings.php', function() {
audio.play();
$el.fadeIn('slow');
});
}, 20000);

关于jquery - jquery 中的方法链音频属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58823603/

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