三.JavaScript 函数

xiaoxiao2021-02-28  38

        函数就是包裹在大括号中的代码块,函数即对象,函数可以嵌套在其他函数中定义.   

        1.基本表达

    <script>     function test() {     alert("hello");     }     </script> <button οnclick="test()">点击</button>

        2.多参数函数

        

    <script>     function test(para1, para2) {     alert(para1 + para2);     }     </script>     <button οnclick=test('hello','world')>点击</button>

        3.带有返回值的函数

        

    <script>     function test(para1, para2) {     return para2 + para1;     }         var param = test('hello ', 'world');     document.getElementById("demo").innerHTML=param     </script>
转载请注明原文地址: https://www.6miu.com/read-2613396.html

最新回复(0)