使用 html 标签复制文本
Copy text with html tags
我正在使用文本编辑器 - quilljs。问题是无法 POST 编辑器内容。这就是为什么我必须 copy/clone 所有编辑器内容到虚构的隐藏输入字段并使用它来 post 文本。
问题是我无法将设计标签(粗体、下划线等)复制到虚拟输入字段。
我能做什么?
<div id="standalone-container">
<div id="editor-container"></div>
</div>
<input type="text" name="testMsg" id="testMsg">
JS
$('#editor-container').on('keyup', function() {
$('#testMsg').val($(this).text());
});
试试这个。在我的示例中,在提交表单之前,我使用 jquery 使用编辑器内容填充了隐藏的输入。您可以通过将 return true 更改为 false 并检查隐藏的输入是否包含某些内容来确定它是否有效。
var quill = new Quill('#editor', {
theme: 'snow'
});
$('#form').on('submit', function (){
var content = quill.container.firstChild.innerHTML
$('#editor-input').val(content)
return true
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<form id="form">
<div id="editor"></div>
<input id="editor-input" type="hidden" />
<button type="submit">Submit</button>
</form>
我正在使用文本编辑器 - quilljs。问题是无法 POST 编辑器内容。这就是为什么我必须 copy/clone 所有编辑器内容到虚构的隐藏输入字段并使用它来 post 文本。
问题是我无法将设计标签(粗体、下划线等)复制到虚拟输入字段。
我能做什么?
<div id="standalone-container">
<div id="editor-container"></div>
</div>
<input type="text" name="testMsg" id="testMsg">
JS
$('#editor-container').on('keyup', function() {
$('#testMsg').val($(this).text());
});
试试这个。在我的示例中,在提交表单之前,我使用 jquery 使用编辑器内容填充了隐藏的输入。您可以通过将 return true 更改为 false 并检查隐藏的输入是否包含某些内容来确定它是否有效。
var quill = new Quill('#editor', {
theme: 'snow'
});
$('#form').on('submit', function (){
var content = quill.container.firstChild.innerHTML
$('#editor-input').val(content)
return true
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdn.quilljs.com/1.3.6/quill.snow.css" rel="stylesheet">
<script src="https://cdn.quilljs.com/1.3.6/quill.js"></script>
<form id="form">
<div id="editor"></div>
<input id="editor-input" type="hidden" />
<button type="submit">Submit</button>
</form>