我需要一个应该是的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/