单击HTML“<audio>”元素

时间:2017-06-19 06:49:07

标签: javascript php jquery html ajax

当用户登录他/她可以听音乐时,我正在开展一个项目。直到这里它的罚款,但我想存储用户关于他听过哪首歌的历史。我已经尝试过使用jquery alert但是这个点击事件不起作用。请建议我一个方法。这是我项目的形象......

Image

以下是HTML代码:显示音乐数据

<?php
         include('code/Confim_login.php'); //ITS FILE NAME

        $login = new Confim_login();   // CREATED THE OBJECT 
  ?>
    <div class="table-responsive">
            <table class="table table-hover table-bordered table-condensed" id="music_library">
                <thead>
                    <tr>
                        <th width="8%">#</th>
                        <th title="added date">Date</th>
                        <th>Name</th>
                        <th>User Added</th>
                        <th>Music</th>
                        <th>Action</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                        $login->show_music();
                    ?>
                </tbody>
            </table>
        </div>

这是jquery事件

<script>
    $(document).ready(function(){
       $(".musicid").click(function(){
          alert('clicked');
       });
      });
</script>

这是PHP代码

<?php
 function show_music(){
            $data = "";
            if($_SESSION['user_logged'][0]['login_type'] == "Admin"){
                $data .= 'del_single_btn';
            }
            else
            {
                $data .= '';
            }

            $sql = "SELECT * FROM music_library WHERE status=1";

            $res = $this->link->query($sql);
            $k=1;

            if($res->num_rows > 0){

                while($row = $res->fetch_assoc()){
        ?>
                    <tr>
                        <td><?php echo $k;?></td>
                        <td><?php echo $row['added_date'];?></td>
                        <td><?php echo $row['music_name'];?></td>
                        <td><?php echo $row['user_added'];?></td>
                        <td>
                            <audio class="musicid" id="<?php echo $row['id'];?>" controls>
                                <source src="code/<?php echo $row['file_path'];?>" type="audio/mpeg" >
                                Your browser does not support the audio element.
                            </audio>
                        </td>
                        <td><button class="btn btn-default <?php echo $data?>" style="border:1px solid #d9534f;color:#d9534f;" id="<?php echo $row['id'];?>">Delete</button></td>
                    </tr>
        <?php
                    $k++;
                }
            }
            else
            {
        ?>
                <tr>
                    <td colspan="6">No Music Files Found</td>
                </tr>
        <?php   
            }
        }

?>

感谢提前

1 个答案:

答案 0 :(得分:0)

<audio onplay="myFunction(this.data-music-id)">...</audio>

和里面

myfunction(id){
song_id = id;
get the id and send the ajax
}