JS基础教程2

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~

相关文章
相关标签/搜索