输入保存textarea值的键 [英] enter key for save textarea values

查看:249
本文介绍了输入保存textarea值的键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有ckeditor和一个按钮用于保存ckeditor文本与ajax。

hi i have ckeditor and one button for save ckeditor text whith ajax .

<textarea id="editor1" name="editor1"></textarea>
<input type="button" name="send" id="send" value="Send" onclick="save()">

我想要删除按钮,当键按下输入保存文本ajax(运行保存功能)
但是当在ckeditor中断时输入。

i want remove button and when key press enter save text whith ajax ( run save function ) but when press enter in ckeditor line break . and how use enter exchange button?

<textarea id="editor1" name="editor1"></textarea>
if (enter press in any where web page ) do save();


推荐答案

重要的是CKEditor中的内容是iframe,所以尝试检查当前文档上的按键的解决方案将失败。

The important part is that the content in CKEditor is an iframe, so those solutions that try to check key presses on the current document will fail.

解决方案就像使用CKEditor事件一样简单,而不依赖于任何外部库:

The solution is as simple as this using the CKEditor events and without relying on any external library:

var editor = CKEDITOR.replace('editor1');  

editor.on('key', function(ev) {
   if (ev.data.keyCode==13)
   {
       ev.cancel();
       console.log('enter');
   }       
});

您可以在这里测试: http://jsfiddle.net/zjkSR/
(看看你的控制台)

You can test it here: http://jsfiddle.net/zjkSR/ (look at your console)

这篇关于输入保存textarea值的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆