我想在每一行中创建一个带有字符串和按钮(播放声音)的表格,并且每个按钮都会播放不同的声音。用javascript播放声音
我想用这种方法来做到这一点:
<script>
function EvalSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.Play();
}
</script>
<embed src="success.wav" autostart=false width=1 height=1 id="sound1"
enablejavascript="true">
,这是按钮:
<form>
<input type="button" value="Play Sound" onClick="EvalSound('sound1')">
</form>
的问题是,我想在这里:
<input type="button" value="Play Sound" onClick="EvalSound('sound1')">
写的fil e URL而不是'sound1',可以这样做吗?或者我需要更改代码中的其他东西?
编辑:
我建立这样的脚本:
<script>
function EvalSound(soundobj) {
var embed = document.createElement('embed');
embed.setAttribute('width',1);
embed.setAttribute('height',1);
embed.setAttribute('src',soundobj);
embed.setAttribute('autostart', false);
embed.setAttribute('enablejavascript', true);
embed.Play();
}
</script>
,并称之为:
<form>
<input type="button" value="Play Sound" onClick="EvalSound('sound url')">
</form>
,它仍然不能播放声音。
我编辑我的文章,你可以看看变化? – MTA 2012-01-31 12:12:43
不要忘记检查此页面,因为该解决方案删除了与锚点关联的文本:http://forum.codecall.net/topic/49572-play-sound-on-click/ – dialex 2013-03-02 14:01:11