我有以下 Tinymce 配置设置:
//set up a new editor function
setup : function(ed) {
//peform this action every time a key is pressed
ed.onKeyUp.add(function(ed, e) {
//setting our max character limit
tinymax = 10;
//grabbing the length of the curent editors content
content = ed.getContent();
var content_text = $(content).text();
var tinylen = content_text.length;
//if the user has exceeded the max, trigger enter and create a new paragraph
if (tinylen>tinymax){
var e = jQuery.Event("keydown");
e.which = 13; // Enter keyCode
$(".content").trigger(e);
}
}
不起作用的是触发事件。我在这里做错了什么? 顺便说一下(“.content”)是文本区域的名称,我也尝试过(ed)但没有成功。
最佳答案
我将尝试回答。您触发事件的方式是正确的。我这里有一个例子,证实它有效。 http://jsfiddle.net/3WsJE/
当使用 jQuery 触发“返回”键时,该键实际上并未输入到文本区域的值中。
我不知道这是否是您想要的,但如果您打算触发 Enter 键来简单地插入换行符,您可以尝试此解决方案。
$(".content").val( $(".content").val()+'\n');
关于javascript - 触发 Tinymce 上的按键事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15560191/