javascript $(文档).on('点击')在html中不起作用

时间:2017-01-16 12:27:34

标签: html document

下面是我的.html代码文件,它似乎根本没有点击点击功能......我错过了什么?

我是新手,对此有任何帮助都会很棒!!

<html>
<body>
    <h1> hello </h1>
    <audio id="audio">
    <source src="http://dl.dropbox.com/u/1538714/article_resources/song.ogg"     type="audio/aac">
    </audio>

<script type="text/javascript">
function dosomething(){
    $('body').append('document click<br />');
    document.getElementById('audio').play();};
    $(document).on('click', function(){dosomething()});
</script>
</body>
</html>

1 个答案:

答案 0 :(得分:1)

您需要先添加jQuery库

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

&#13;
&#13;
<html>
<body>
    <h1> hello </h1>
    <audio id="audio">
    <source src="https://dl.dropboxusercontent.com/u/40410302/rainbowride.aac"     type="audio/aac">
    </audio>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<script type="text/javascript">
function dosomething(){
    $('body').append('document click<br />');
    document.getElementById('audio').play();};
    $(document).on('click', function(){dosomething()});
</script>
</body>
</html>
&#13;
&#13;
&#13;