当前位置:网站首页>JS基础2
JS基础2
2022-06-28 10:49:00 【程序员社区】
函数:一段代码的封装,主要用于实现某个功能(函数是代码封装和复用的体现)
定义
声明式function函数名(){函数体}调用:函数名()
注:函数不会主动执行,需要调用
表达式let|var函数名=functtion(){函数体 }调用:函数名()
注:声明式调用可以在函数定义之前,表达式不可以
带参函数的定义
实现已知数据功能代码
在定义函数的小括号处,填入形参,多个用逗号隔开
在调用函数的小括号处填入实参
形参和实参关系
形参和实参在个数,顺序,数据类型上都要保持一致
如果实参小于形参,形参值为undefined
变量作用域
全局变量:全局可用。函数体外通过var定义的,或者在函数体内部没有用关键字直接就定义的变量
局部变量:在函数体内部定义的变量
函数的返回值
当需要函数的结果进行下一步运算时,明确要求返回的时候需要用到返回值function函数名(){ 函数体return 变量,值,表达式;}调用:函数名()
注:return一旦执行,后面的代码就不会再执行,
函数如果没有return,那么函数返回值为underfined
预编译
函数在逐行执行之前,会先进行预编译
变量提升:将变量声明的代码提升到作用域最前面
- var定义的变量
- 声明式定义的函数
- return后面的语句
- if里面语句(即使条件不成立,也会变量提升)
arguments
- 函数自带对象:记录函数参数相关性息
- 获取函数实参个数arguments.length
- 获取具体某个实参arguments[对应实参的索引]
注:索引从0开始
递归函数
递归函数:函数自己调用自己
注:递归必须要有结束
常用事件
- 获取元素节点
document.getElementById('id名') - 获取元素属性
元素节点.属性名 - 设置元素属性
元素节点.属性名=属性值 - 绑定事件
元素节点.on事件类型=function (){要执行代码}
常见事件类型
| 事件 | 含义 |
|---|---|
| onclick | 点击 |
| onlode | 页面加载完成 |
| onmouseover | 鼠标悬停 |
| onmouseout | 鼠标移出 |
边栏推荐
- 丢弃 Tkinter!简单配置快速生成超酷炫 GUI!
- 【力扣——动态规划】整理题目1:基础题目:509、70、746、62、63、343、96(附链接、题目描述、解题方法及代码)
- As shown in the figure, the SQL row is used to convert the original table of Figure 1. Figure 2 wants to convert it
- 物联网无线通信应用中6种融合定位技术
- Realize an air conditioner with compose to bring you cool in summer
- Generate token
- Katalon框架测试一个web页面操作实例代码
- Metersphere实现UI自动化元素不可点击(部分遮挡)
- How to use K-line diagram for technical analysis
- [unity][ecs] learning notes (III)
猜你喜欢

Threads and thread pools

Set up your own website (11)

Sqlcmd database connection error

Metersphere implements UI automation elements that are not clickable (partially occluded)

Katalon framework tests web (XX) custom keywords and upload pop-up operations

DataEase安装升级

Dataease installation upgrade

To enhance the function of jupyter notebook, here are four tips

Internet of things application case of wireless module transparent transmission technology

The boss asked me to write an app automation -- yaml file reading -- with the whole framework source code attached
随机推荐
Set up your own website (11)
港伦敦金行情走势图所隐藏的信息
Katalon framework tests web (XX) custom keywords and upload pop-up operations
Understand 12 convolution methods (including 1x1 convolution, transpose convolution and deep separable convolution)
[200 opencv routines] 213 Draw circle
BLE蓝牙模块NRF518/NRF281/NRF528/NRF284芯片方案对比
Ribbon核心源码解析
MySQL(二)
工控安全之勒索病毒篇
idea连接sql sever失败
Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
datetime与logging模块
Realize an air conditioner with compose to bring you cool in summer
[function suggestion] select a space when multiple workspaces are started
MySQL common commands for viewing database performance
Realization of a springboard machine
知道 Redis RDB 这些细节,可以少踩很多坑
Move command
[monkey] Introduction to monkey test
DlhSoft Kanban Library for WPF