hello,我是愛學編程的小圓子,好久沒更新了呢,emmmmmmm.......
今天我們來學function function_name(...) {}
function是觸發事件的時候觸發{}里面的代碼的代碼
廢話不多說,上模板
<!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()
然后
function
負責執行代碼
它的語法是function function_name() {}
好了,下一期我們學getElementById/getElementByTagName/getElementClass
但是注意,javascript區分大小寫,function不能寫成FUNCTION或Function
好了,有什么問題可以在評論區留言
Bye~
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/96606.html
標籤:JavaScript
下一篇:什么是json
