<audio> src 随 javascript 变化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4935101/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
<audio> src change with javascript
提问by Aliénor Latour
I want to change the src attribute of a tag using javascript and a button :
我想使用 javascript 和按钮更改标签的 src 属性:
<audio id="playme" src="" controls="controls">Your browser...</audio>
And a little further down the page :
再往下一点:
<input type="button" style="font-size: 10px;"
OnClick="document.getElementById('playme').src='snd/SOUND.WAV';"
value="Listen">
It seems to just do nothing. Anyone has a clue ? Thanks a million
它似乎什么都不做。任何人都有线索?太感谢了
Using Firefox 3.6 on Xubuntu 10.10
在 Xubuntu 10.10 上使用 Firefox 3.6
EDIT: it seems to work on Chrome but Firefox doesn't like it. Should I report a bug ? Do you know a way to bypass that ?
编辑:它似乎适用于 Chrome,但 Firefox 不喜欢它。我应该报告错误吗?你知道绕过那个的方法吗?
回答by lonesomeday
I believe you have to tell the browser to load the new file when you change the srcattribute, by calling load:
我相信您必须src通过调用来告诉浏览器在更改属性时加载新文件load:
var playme = document.getElementById('playme'); playme.src='snd/SOUND.WAV'; playme.load();

