jquery - 可编辑的 DIV HTML CSS

标签 jquery html css jquery-ui css-selectors

我需要一个应该是的div 1.可调整大小和 2. 可编辑。

并且应该在 IE 和 Chrome 中工作。

因此,如果我开始在 div 中进行编辑,并且到达该 div 中行的末尾,则光标应移至下一行。我如何实现它。

下面是我试过的代码,它在 IE 中确实有效,但不正确。 但是它不适用于 chrome。任何帮助,将不胜感激。谢谢!

$("#resizable").resizable();
#resizable {
  width: 500px;
  height: 500px;
  background: #ccc;
}
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<body contenteditable="false">


  <div id="resizable" contenteditable="true"></div>

最佳答案

无论出于何种原因,chrome 都会将您在框中键入的内容添加到右侧的拖动 handle 。您可以使用 create 回调来禁用拖动 handle 上的内容编辑以使其在 chrome 中工作。

$("#resizable").resizable({
  create: function( event, ui ) {
    this.childNodes.forEach(function(child){
      child.contentEditable = false;
    });
  }
});
#resizable {
  width: 500px;
  height: 500px;
  background: #ccc;
}
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<body contenteditable="false">


  <div id="resizable" contenteditable="true"></div>

关于jquery - 可编辑的 DIV HTML CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49113842/

相关文章:

jquery - 如何在 jQuery 中链接匿名函数?

html - float div 宽度的 MPDF 问题

html - Bootstrap 上的 CSS 媒体查询不适用于 iPhone

javascript - 为什么我的 div 链接会链接到我的其他内容?

javascript - 使用 JavaScript 添加复选框值 PHP、MySQL 和警报框

jquery - IE7 和 8 不触发附加在表内的元素的 jQuery 单击事件

css - 使用 CSS 过渡平滑 javascript 驱动的快速位置变化?

javascript - 事件停止重复

javascript - 在网站中点击“赞”应该在 Facebook 中点击“赞”

html - 我怎样才能更好地平滑这种悬停效果?