js代码写在html的script块中
js的函数格式:
function 函数名()
{
代码
}
(调用)函数名;
html代码操作:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <script> 7 function f() { 8 alert('aaaaaa'); 9 } 10 11 f(); 12 </script> 13 </head> 14 <body> 15 16 </div> 17 18 </body> 19 </html>
效果:打开浏览器弹出aaaaaa的对话框。
注意:
- js的函数传参不需要写变量类型
- 传字符串需要 函数名('abc')
- 传高度、宽度之类的传入'100px'