ueditor的ctrl+enter和enter切换提交并且禁止换行

本文介绍了一种使用JavaScript监听键盘事件的方法,特别是如何通过监听Ctrl+Enter和Enter键来触发特定功能。文中详细解释了如何捕获按键事件并根据不同的按键组合执行相应操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var pre_code = null;var Kf = {post_type:1}; this.UE.addListener("keydown", function (type, e) { //这里的focus可以视自己的情况定,可以使blur,keypress等等 // 兼容FF和IE和Opera var theEvent = e || window.event; var code = theEvent.keyCode || theEvent.which || theEvent.charCode; //设置按下了ctrl+enter键发送 if(KF.post_type == 2) { if(pre_code == null) { //按下第一个键,储存 pre_code = code; return true; } else { //按下第二个键 if((pre_code == 13 && code == 17) || (pre_code == 17 && code == 13)) { preventBr(); //初始化 pre_code = null; //写一些逻辑...... return false; } else { pre_code = null; return true; } } } //设置按下了enter发送 else if(KF.post_type ==1 && code == 13 ) { preventBr(); ////初始化 pre_code = null; //写一些逻辑...... return false; } else { pre_code = null; return true; } //阻止换行事件 function preventBr() { e.cancelBubble=true; e.preventDefault(); e.stopPropagation(); } });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值