如何将夏季笔记的内容(文本)传递给<p>标签



function PasarValor() {

var htmlContent = $('#summernote').summernote('code');
document.getElementById("idTitulo").innerHTML = $(htmlContent).text();
// document.getElementById("idTitulo").innerHTML = document.getElementById("summernote").value;

}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>bootstrap4</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote-bs4.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.11/summernote-bs4.js"></script>

</head>
<body>
<p id="idTitulo">
ESCRIBE ENCABEZADO....
</p>
<div id="summernote" onkeyup="PasarValor();"></div>
<script>
$('#summernote').summernote({
toolbar: [
['style', ['style']],
['font', ['bold', 'italic', 'underline', 'clear']],
['fontname', ['fontname']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['help', ['help']]
],
width: 530,
});
</script>
</body>
</html>

我想把我写在summernote中的文本和它所具有的选项一起传递,例如,如果文本是红色的,我想把所有文本复制到p标记中,该标记具有summernote中应用的属性(如红色、对齐等(。

首先你应该把问题翻译成英语,第二个summernote有一个callback属性,可以让你听到事件,所以在初始化时你可以添加带有你想要的事件的回调

$('#summernote').summernote({
toolbar: [
['style', ['style']],
['font', ['bold', 'italic', 'underline', 'clear']],
['fontname', ['fontname']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['help', ['help']]
],
width: 530,
//add the callback with the event
callbacks: {
//listen to keyup
onKeyup: function() {
//lastly we get the editor html with $('#summernote').summernote('code') and paste it in the #idTitulo 
$('#idTitulo').html($('#summernote').summernote('code'))
}
}
});

最新更新