实例代码“Ctrl+/”提示“F11/ESC”全屏 返回 格式化 恢复 运行
x
 
1
<!DOCTYPE html>
2
<html>
3
<head>
4
    <title>Dynamic Script Example</title>
5
</head>
6
<body>
7
    <p>You should see an alert saying &quot;hi&quot; after clicking the button.</p>
8
    <input type="button" value="Add Script" onclick="addScript()">
9
10
    <script type="text/javascript">
11
        function addScript(){
12
            var script = document.createElement("script");
13
            script.type = "text/javascript";
14
            script.text = "function sayHi(){alert('hi');}";
15
            document.body.appendChild(script);
16
            sayHi();
17
        }
18
19
    </script>
20
</body>
21
</html>