有没有办法让 Enter 和 Shift + Enter 在 TinyMCE 中以相同的方式工作? [英] Is there a way to make Enter and Shift + Enter work the same way in TinyMCE?

查看:27
本文介绍了有没有办法让 Enter 和 Shift + Enter 在 TinyMCE 中以相同的方式工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在当前项目中使用 tinymce-react 包.有没有办法让进入"?和shift + enter"以同样的方式工作?在我的情况下,我需要它们都在按下时插入 <p></p> .我尝试了 force_root_blockforce_p_newlinesforce_br_newlines 的不同变体,但结果总是其中之一插入 <p></p> 和另一个
.在此先感谢您的帮助:)

I'm using tinymce-react package in my current project. Is there a way to make "enter" and "shift + enter" work the same way? In my case I need them both to insert <p></p> when pressed. I tried different variations of force_root_block, force_p_newlines and force_br_newlines but it always ends up that one of them insert <p></p> and the other one <br/>. Thanks in advance for help :)

推荐答案

您在寻找这样的东西吗?

Are you looking for something like this?

//target textarea with querySelector
var textA = document.querySelector("textarea");
textA.addEventListener("keyup", function(event) {
  // keyCode 13 is the "Enter" key on the keyboard
  // keyCode 16 is the "Shift" key on the keyboard
  if (event.keyCode === 13 || event.keyCode === 16) {
    // Prevent default action
    event.preventDefault();
    //if shift or enter are pressed then insert new paragraph
    textA.value = textA.value + "<p></p>"
  }
});

<textarea></textarea>

这篇关于有没有办法让 Enter 和 Shift + Enter 在 TinyMCE 中以相同的方式工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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