hello,我是愛學編程的小圓子。很久沒更新了呢,emmmmmmm.......javascript
今天咱們來學function function_name(...) {}html
function是觸發事件的時候觸發{}裏面的代碼的代碼java
廢話很少說,上模板編程
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>HTML</title> </head> <body> <button type="button" onclick="button()">點我試試</button> <!-- 也能夠替換成input,可是type值是button,type必填 --> </body> <script type="text/javascript> function button() { //這裏只要點擊按鈕就執行這裏的代碼 alert("hi!") } </script> </html>
它的原理是你一點擊按鈕就會觸發事件button()spa
而後code
function
負責執行代碼htm
它的語法是function function_name() {}blog
好了,下一期咱們學getElementById/getElementByTagName/getElementClass事件
可是注意,javascript區分大小寫,function不能寫成FUNCTION或Functionip
好了,有什麼問題能夠在評論區留言
Bye~