当前位置:网站首页>常用的鼠标事件和键盘事件
常用的鼠标事件和键盘事件
2022-07-23 07:06:00 【抱抱旋旋子】
常用鼠标事件
一.禁止选中文字和禁止右键菜单
1.禁止鼠标右键菜单
contextmenu主要控制应该何时显示上下文菜单,主要用于程序员取消默认的上下文菜单

2.禁止鼠标选中( selectstart开始选中)

例子:
二.获得鼠标在页面中的坐标
鼠标事件对象
event对象代表事件的状态,跟事件相关的一系列信息的集合。现阶段我们主要是用鼠标事件对象MouseEvent和键盘事件对象KeyboardEvent。
例子: 
三.跟随鼠标的天使
案例分析:
1.鼠标不断的移动,使用鼠标移动事件: mousemove在页面中移动,给document注册事件
2.图片要移动距离,而且不占位置,我们使用绝对定位即可
3.核心原理:每次鼠标移动,我们都会获得最新的鼠标坐标,把这个x和y坐标做为图片的top和left值就可以移动图片

常见的键盘事件

注意:
1.如果使用addEventListener不需要加on
2. onkeypress和前面2个的区别是,它不识别功能键,比如左右箭头,shift等。
3.三个事件的执行顺序是:keydown -- keypress --- keyup

四.keyCode判断用户按下哪个键


注意:
onkeydown和onkeyup 不区分字母大小写,onkeypress区分字母大小写。在我们实际开发中,我们更多的使用keydown和keyup,它能识别所有的键(包括功能键)Keypress不识别功能键,但是keyCode属性能区分大小写,返回不同的ASCII值
五.模拟京东按键输入内容
1.快递单号输入内容时,上面的大号字体盒子(con)显示(这里面的文字
2.同时把快递单号里面的值( value )获取过来赋值给con盒子( innerText )做为内容
3.如果快递单号里面内容为空,则隐藏大号字体盒了(con)盒子
4.注意::keydown和keypress在文本框里面的特点∶他们两个事件触发的时候,文字还没有落入文本框中
5.keyup事件触发的时候,文字已经落入文本框里面了
6.当我们失去焦点,就隐藏这个con盒子
7.当我们获得焦点,并且文本框内容不为空,就显示这个con盒子

边栏推荐
- 数据库系统原理与应用教程(039)—— MySQL 查询(一):SELECT 命令的语法分析
- Power bi - Comprehensive Application
- 数据库系统原理与应用教程(044)—— MySQL 查询(六):使用 LIMIT 选项实现分页查询
- Introduction to radar part vii 4 SAR system design
- freemarker
- Optimising a 3D convolutional neural network for head and neck computed tomography segmentation with
- Remote editing and debugging with vscode
- 【PART 2】OAK-D+TurtleBot3机器人项目全解析
- 接口测试-简单的接口自动化测试Demo
- PHP gets the current timestamp three bit MS MS timestamp
猜你喜欢

Power bi - Comprehensive Application

离屏渲染 &FBO

【 Visual Dispatching Software】 Shanghai Dow Ning apporte netronic download, Trial, tutoriel pour l'Organisation SMB

In depth interpretation of EVM's ecological Empire

内存取证之NSSCTF-OtterCTF 2018(复现赛)

php连接sql server

第二章关系数据库课后习题

2022暑假软件创新实验室集训 项目实战1

Point target simulation of SAR imaging (III) -- Analysis of simulation results

Google play app store may delete the overview of APP permissions and use a new combination of data security information
随机推荐
Kotlin - Job 任务/取消
【MUDUO】Poller抽象类
数据库系统原理与应用教程(050)—— MySQL 查询(十二):SELECT 命令的执行过程分析
Smart city infrastructure management based on bim+3dgis
养老机构智能视频监控解决方案,用新技术助力养老院智慧监管
数据库系统原理与应用教程(042)—— MySQL 查询(四):使用通配符构造查询条件
数据库系统原理与应用教程(047)—— MySQL 查询(九):连接查询
概率沉思錄:2.The quantitative rules
Unity about local loading pictures involves webrequest or byte
Probability meditation: 2. The quantitative rules
[Part 2] full analysis of oak-d+turnlebot3 robot project
【PART 2】OAK-D+TurtleBot3机器人项目全解析
数据库系统原理与应用教程(043)—— MySQL 查询(五):对查询结果排序
prometheus+node-exporter+grafana 监控服务器系统资源
PHP gets the current timestamp three bit MS MS timestamp
微信小程序--动态设置导航栏颜色
Interface test - simple interface automation test demo
SeekTiger的Okaleido有大动作,生态通证STI会借此爆发?
概率沉思录:2.The quantitative rules
QNX modify system time
