遇到js的问题

时间:2018-04-27 18:02:11

标签: javascript html css

此脚本从我的按钮中删除所有文本并使其成为绿色块。

var qs = location.search.replace('?', '');  // get querystring and remove question marks
var pairs = qs.split('&');                  // split on ampersand
var items = {};                             // declare object to store key/value pairs

// Loop through pairs and extract the key and the value (and append them to the object)
for (var i = 0; i < pairs.length; i++) {
    items[pairs[i].split('=')[0]] = pairs[i].split('=')[1];
}

console.log(items);
function playSound(soundfile) {
  document.getElementById("musicButton").innerHTML =
    "<embed src=\"" + soundfile + "\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
}

1 个答案:

答案 0 :(得分:1)

这消除了对任何HTML元素的需要。

&#13;
&#13;
function playSound(soundfile) {
  var audio = new Audio(soundfile);
  audio.play();
}
&#13;
<button id="musicButton" class="button" type="button" name="music" onmouseover="playSound('MySong.wav')">Hover Me For Sick Beats!</button>
&#13;
&#13;
&#13;