简体   繁体   English

我想将第一个函数组合到第二个函数,所以我只能调用它一次

[英]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.

相关问题 我想让第二个 function 等待第一个完成,但我想不出它的语法 - I want to make the second function await the first one to complete but I can’t think of syntax to it 如何仅触发第二个功能中的第一个功能 - How can I trigger only the first function inside second function 我只是希望第二个函数在第一个函数之后运行,依此类推。 html页面中的第一个函数由body onload =“ runOne()”调用 - I simply want the second function to run after the first and so on. the first function is being called in the html page by body onload=“runOne()” 如何撤消 JavaScript function? 第一个 function 有效,但我想用第二个 function 撤消它,但那个不起作用 - How to undo a JavaScript function? The first function works, but I want to undo it with the second function, but that one does not work 我怎样才能仅在一次循环后调用此函数? - How can I call this function only once yet loop as needed? JavaScript-我希望延迟一下按钮,因此每15秒只能单击一次 - JavaScript - I want to but a delay on my button so it can only be clicked once every 15 Seconds 我想按function1,function2和function3之类的顺序逐个打印函数,所以我使用了回调 - I want print the functions one by one in an order like function1 , function2 and function3 so I used call back Javascript调用返回两个值的函数,但我只需要第一个(或第二个) - Javascript calling a function that returns two values but I want only the first (or the second) 第一个动画完成后,调用第二个动画 - Call a second animation once the first one is completed 反应:使用 Axios 所以我可以在我的第二个请求中使用我的第一个请求中的数据 - React: Using Axios so I can use data from my first request in my second one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM