如何在多个按钮上使用此课程?

时间:2017-08-29 01:05:34

标签: javascript jquery html html5

脚本和HTML代码:当我点击按钮时,其他按钮正在工作。我有一个班级的按钮,所以我怎么能使用多个这个按钮? 我应该为每个按钮添加data_id吗?

2 个答案:

答案 0 :(得分:0)

这是你需要的吗?



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<audio controls>
  <source src="http://www.noiseaddicts.com/samples_1w72b820/4160.mp3" id="audio" type="audio/ogg">
  Your browser does not support the audio element.
</audio>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

尝试向标记添加新类。并通过新类在JQuery上获取元素,如下所示:

&#13;
&#13;
    function play() {
        var audio = document.getElementById('audio');
        if (audio.paused) {
            audio.play();
             $('.play-button').addClass('icon-control-pause')
            $('.play-button').removeClass('icon-control-play')
                  
        }else{
            audio.pause();
            $('.play-button').addClass('icon-control-play')
            $('.play-button').removeClass('icon-control-pause')

  
        }
    }
&#13;
 

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  
   <audio src="audio.mp3" id="audio"></audio>
<i class="play-button icon-control-play i-2x" id="play" onclick="play()"></i>
&#13;
&#13;
&#13;