Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
562 views
in Technique[技术] by (71.8m points)

kindeditor富文本编辑器通过按钮获取内容显示,怎么改成直接同步显示?

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Default Examples</title>
<script type="text/javascript" src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
<script charset="utf-8" src="./kindeditor/kindeditor-all-min.js"></script>
<script charset="utf-8" src="./kindeditor/lang/zh-CN.js"></script>
<script>
//KindEditor富文本编辑器样式初始化
    KindEditor.ready(function(K) {
      window.editor = K.create('#seditor');
    });
</script>
</head>
<body>
    <h3>默认模式</h3>
    <textarea id="seditor" name="content" style="width: 800px; height: 400px;" οnkeyup="SwapTxt()">KindEditor</textarea>
    <input value="点击获取编辑器的内容" onclick="getContent()" type="button">
    <h3>展示区</h3>
    <div id="show" style="border:1px solid red;width:600px;height:500px;word-break:break-all;"></div>

<script type="text/javascript">
    function getContent(){
        editor.sync();
        $('#show').html($('#seditor').val());
    }
</script>
</body>
</html>

image
像图片中这样,需要点击“点击获取编辑器的内容”按钮,下面展示区才会显示里面的内容,想要不通过按钮,直接div同步获取显示要怎么修改JS?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
KindEditor.ready(function(K) {
  window.editor = K.create('#seditor',{
    afterChange: function(){
       Promise.resolve(true)
       .then(function(){
           window.editor.sync();
           $('#show').html($('#seditor').val());
       })
    }
  });
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...