一,效果图。

\"\"

二,代码。

\"复制代码\"
<!DOCTYPE html>
<html>

<head>
    <  charset=\"utf-8\">
    < >  函数</ >
</head>

<body>
    <p>点击这个按钮,来调用带参数的函数。</p>
    <button  =\"myFunction(\'Harry Potter\',\'Wizard\')\">点击这里</button>
    < >
    function myFunction(name, job) {
        alert(\"Welcome \" + name + \", the \" + job);
    }
    </ >
    <p>本例调用的函数会执行一个计算,然后返回结果</p>
    <p id=\"demo\"></p>
    <  type=\"text/ \">
    function myFunction(a, b) {
        return a * b;
    }

    document.getElementById(\"demo\").innerHTML = myFunction(4, 3);
    </ >
</body>

</html>

\"复制代码\"

 参考资料:《菜鸟教程》

收藏 打印