Textarea value change when summernote div is changed

前端 未结 6 1557
独厮守ぢ
独厮守ぢ 2021-02-05 09:37

I have setup a div for the summernote to alter text pulled from a database.

6条回答
  •  后悔当初
    2021-02-05 10:07

    I think it is better to handle the onChange event.

    v0.7.0

    $('#summernote').summernote({
      callbacks: {
        onChange: function(contents, $editable) {
          console.log('onChange:', contents, $editable);
        }
      }
    });
    

    $(document).ready(function(){
    
        $("#summernote").summernote(
            {
                height: "10em",
                callbacks: {
                  onChange: function (contents, $editable) {
                    var code = $(this).summernote("code");
                    $("#lawsContent").val(code);
                  }
                }
            }
        );
    
    });
    #lawsContent
    {
        width: 100%;
        height: 10em;
    }
    
    
    
     
    
    
    
    
    
    Editor:
    
    Output:

    v0.6.5

    As of this version, callback only works with camel case string.

    $('#summernote').summernote({
      onChange: function(contents, $editable) {
        console.log('onChange:', contents, $editable);
      }
    });
    

    $(document).ready(function(){
    
        $("#summernote").summernote(
            {
                height: "10em",
                onChange: function (contents, $editable) {
                    $("#lawsContent").val(contents);
                }
            }
        );
    
    });
    #lawsContent
    {
        width: 100%;
        height: 10em;
    }
    
    
    
    
    
    
    
    
    
    Editor:
    
    Output:

提交回复
热议问题