[英]I want to combine first function to the second one, so I can call it only once
I want to combine first function to the second one, so I can call it only once. 我想将第一个函数组合到第二个函数,所以我只能调用它一次。 Basically i have 2 html5 audio files that im playing. 基本上我有2个html5音频文件即时播放。 Everything works fine.But if i play my first audio and during that time if i click the second audio the pause button on first audio doesn't change to default(off) 一切正常。但是,如果我播放我的第一个音频,在此期间,如果我点击第二个音频,第一个音频上的暂停按钮不会更改为默认(关闭)
//First function
function toggleState(item) {
if (item.className == "play") {
item.className = "pause";
} else {
item.className = "play";
}
}
//Second function
// Play stop Music
function EvalSound(soundobj) {
var thissound = document.getElementById(soundobj);
if (thissound.paused) {
thissound.play();
} else {
thissound.pause();
}
}
This question was answered in question by its owner with the following solution: 该所有者通过以下解决方案回答了该问题:
I Managed to fixed it like this. 我管理这样修理它。
function toggleState(item, soundobj) {
var thissound = document.getElementById(soundobj);
if (item.className == "play") {
thissound.play();
item.className = "pause";
} else {
thissound.pause();
item.className = "play";
}
}
I Also managed to get the current track list title. 我还成功获得了当前的曲目列表标题。 For Example, you click on a song and it will display after , say like "Now playing blablabla song". 例如,你点击一首歌后会显示,比如说“正在播放blablabla歌曲”。
I show you a working example below. 我将在下面向您展示一个工作示例。
HTML: HTML:
<option id="1" title="Now Playing." value="URL.mp3">Song name</option>
Javascript: 使用Javascript:
audioURL = document.getElementById('mylist');
var f = audioURL.options[audioURL.selectedIndex].title; //Here is title
document.getElementById("demo").innerHTML = f; //output to f at demo elem.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.