doujia2090 2016-08-07 13:18
浏览 42
已采纳

上传功能不起作用?

Onload function is not working.I cannot play the song automatically when the song is loaded.Here is my view.

<div class="main" onload="enableAutoplay()">
    <div class="audio-name">
        <h1><?php echo str_replace('_',' ',$name);?></h1>


    </div>





        <center>
            <audio id="audio" controls="controls" >
                    <source src="<?php echo base_url();?>musics/<?php echo $name;?>"  type="audio/mp3" >

            </audio>
        </center>
        <center><a href="<?php echo base_url();?>admin/audio/showaudio" class='back'>Back to All song list</a></center>
    </div>

<script>

            var vid = document.getElementById("audio");
        function enableAutoplay() {
            vid.autoplay = true;
            vid.load();
        }

        function disableAutoplay() {
            vid.autoplay = false;
            vid.load();
        }

        function checkAutoplay() {
            alert(vid.autoplay);
        }
</script>

i like to play the song when user click the song name.but here user have to click the "play" button to play the song.

  • 写回答

2条回答 默认 最新

  • douweng1935 2016-08-07 13:35
    关注

    The onload event can only be used on the body itself, frames, images, and scripts. In other words, it can be attached to only body and/or each external resource. The div is not an external resource and it's loaded as part of the body, so the onload event doesn't apply there.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于单片机数字电压表电路组成及框图
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line