下面就讓我們用代碼說話。
首先我們將一個函數(shù)賦值給一個變量
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <script> var a = function ass(){alert("hello")}; //將函數(shù)賦值給變量 </script> <body> </body> </html>
然后我們在按鈕中添加單擊事件,并通過變量來調(diào)用這個函數(shù)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <script> var a = function ass(){alert("hello")}; //將函數(shù)賦值給變量 </script> <body> <button onclick="a()" >單擊事件</button> </body> </html>
最后我們來看一下效果
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com