2017-01-16 18 views
0

下面是我的.html代碼文件,它似乎沒有toload的點擊功能..我錯過了什麼?

我對此很陌生,對此的任何幫助都會很棒!

<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> 
+0

請與下面的答案,你已經錯過了jQuery庫 –

回答

1

您需要添加jQuery庫第一

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

<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>

+0

這完美的作品!檢查非常感謝!! :-) – 2060754z

+0

@ 2060754z請在答案中打勾如果它爲你工作 –

+1

我會在時限後:-) – 2060754z

相關問題