就像我在标题中所说。我想播放不同的声音,但出于某种原因,播放声音后按钮上的文字会消失。按钮仍然有效。我需要按钮保持不动。按钮点击,声音播放,但按钮消失
也有反正不按钮点击时不重新加载页面?
这里是我的代码:
的javascript:
function playSound() {
var sounds = new Array(
"battle.mp3"
);
$("button").html("<embed src=\""+sounds[Math.floor(Math.random()*(sounds.length+1))]+"\" hidden=\"true\" autostart=\"true\" />");
HTML
<div id="element">
<button onclick="javascript:playSound()">Try it</button>
</div>
英雄所见略同! – Daniel
如果我这样做,虽然这个新的元素会被点击后消失不是吗?我也把假回报。在函数结束时,页面会重新加载。 – user1509151