当前位置:网站首页>常用的鼠標事件和鍵盤事件
常用的鼠標事件和鍵盤事件
2022-07-23 13:48: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盒子

边栏推荐
- 数据库-视图详探
- Kotlin - Job 任务/取消
- [Muduo] epollplayer event distributor
- 微服务重点
- 数据库系统原理与应用教程(041)—— MySQL 查询(三):设置查询条件
- ModuleNotFoundError: No module named ‘setuptools_rust‘
- Interviewer: have you learned about the underlying implementation of reentrantlock? tell us your opinion
- Point target simulation of SAR imaging (III) -- Analysis of simulation results
- 2022-07-22 回顾链表操作以及部分问题
- 2022暑假软件创新实验室集训 项目实战1
猜你喜欢

Method of entering mathematical formula into mark down document

China leads the United States in another emerging technology field and stands at the commanding height of scientific and technological innovation
![[play with FPGA in simple terms to learn 10 ----- simple testbench design]](/img/3a/6d2f4f4e35a08803383def9c665df9.png)
[play with FPGA in simple terms to learn 10 ----- simple testbench design]

vs2019:constexpr 函数“qCountLeadingZeroBits”不能生成常量表达式

QT creator.Pro file adds the corresponding library according to the kit

GLIB-CRITICAL g_file_test:assertion ‘filename != null‘ failed

ES6——周考题

Kept dual machine hot standby

In depth interpretation of EVM's ecological Empire

如何保证消息的可靠传输?如果消息丢了会怎么办
随机推荐
Remote editing and debugging with vscode
prometheus+node-exporter+grafana 监控服务器系统资源
Introduction to radar part vii 2 imaging method
面试官:有了解过ReentrantLock的底层实现吗?说说看
回溯法解决 八皇后问题
养老机构智能视频监控解决方案,用新技术助力养老院智慧监管
Chapter II relational database after class exercises
"Computing beast" Inspur nf5468a5 GPU server open trial free application
LeetCode_2341_数组能形成多少数对
Introduction to radar part vii 4 SAR system design
SparkSQL设计及入门,220722,
Changes in the pattern of NFT trading market: from one dominant company to a hundred schools of thought
基于BIM+3DGIS的智慧城市基础设施管理
Ros2 self study notes: gazebo physical simulation platform
[JS advanced] basics of regular expressions - about regular expressions you want to know_ 01
决策树详解
【STM32】串口通信基础知识
What should I do if I use PIP in the virtual environment by default
单例模式实现及防止反射与序列化
ROS中引用和输出消息类型
