如何在点击事件时自动运行 summernote-cleaner

How to auto run summernote-cleaner on click event

提问人:Sa1ne82 提问时间:11/4/2023 更新时间:11/4/2023 访问量:15

问:

简而言之,我希望 summernote-cleaner 在单击按钮时自动运行。老实说,我是一个复制粘贴代码的人。因此,我花了几个小时通过复制粘贴来暴力破解,并砍掉了我在谷歌上搜索的一些代码。看看哪一个有效,但它惨遭失败。

这里是我想触发 summernote-cleaner 的按钮

        <div class="form-group d-flex justify-content-end w-100 form-group">
            <button onclick="return confirm('Are you sure?');" class="btn-primary btn"> Update</button>
            <button class="btn-light btn ml-2" type="button" data-dismiss="modal"> Cancel</button>
        </div>
$(document).ready(function(){
   $('.summernote').summernote({
          dialogsInBody: true,
          fontsize: 18,
          height: 200,
          toolbar: [
              [ 'cleaner',['cleaner']], // The Button
              [ 'font', [ 'bold', 'italic', 'underline', 'strikethrough'] ],
              [ 'color', [ 'color' ] ],
              [ 'para', [ 'ol', 'ul', 'paragraph' ] ],
          ],
          cleaner: {
      action: 'both', // both|button|paste 'button' only cleans via toolbar button, 'paste' only clean when pasting content, both does both options.
      icon: '<i class="note-icon"><svg xmlns="http://www.w3.org/2000/svg" id="libre-paintbrush" viewBox="0 0 14 14" width="14" height="14"><path d="m 11.821425,1 q 0.46875,0 0.82031,0.311384 0.35157,0.311384 0.35157,0.780134 0,0.421875 -0.30134,1.01116 -2.22322,4.212054 -3.11384,5.035715 -0.64956,0.609375 -1.45982,0.609375 -0.84375,0 -1.44978,-0.61942 -0.60603,-0.61942 -0.60603,-1.469866 0,-0.857143 0.61608,-1.419643 l 4.27232,-3.877232 Q 11.345985,1 11.821425,1 z m -6.08705,6.924107 q 0.26116,0.508928 0.71317,0.870536 0.45201,0.361607 1.00781,0.508928 l 0.007,0.475447 q 0.0268,1.426339 -0.86719,2.32366 Q 5.700895,13 4.261155,13 q -0.82366,0 -1.45982,-0.311384 -0.63616,-0.311384 -1.0212,-0.853795 -0.38505,-0.54241 -0.57924,-1.225446 -0.1942,-0.683036 -0.1942,-1.473214 0.0469,0.03348 0.27455,0.200893 0.22768,0.16741 0.41518,0.29799 0.1875,0.130581 0.39509,0.24442 0.20759,0.113839 0.30804,0.113839 0.27455,0 0.3683,-0.247767 0.16741,-0.441965 0.38505,-0.753349 0.21763,-0.311383 0.4654,-0.508928 0.24776,-0.197545 0.58928,-0.31808 0.34152,-0.120536 0.68974,-0.170759 0.34821,-0.05022 0.83705,-0.07031 z"/></svg></i>',
      keepHtml: true,
      keepTagContents: ['span'], //Remove tags and keep the contents
      badTags: ['applet', 'col', 'colgroup', 'embed', 'noframes', 'noscript', 'script', 'style', 'title', 'meta', 'link', 'head'], //Remove full tags with contents
      badAttributes: ['bgcolor', 'border', 'height', 'cellpadding', 'cellspacing', 'lang', 'start', 'style', 'valign', 'width', 'data-(.*?)'], //Remove attributes from remaining tags
      limitChars: 0, // 0|# 0 disables option
      limitDisplay: 'both', // none|text|html|both
      limitStop: false, // true/false
      notTimeOut: 850, //time before status message is hidden in miliseconds
      keepImages: true, // if false replace with imagePlaceholder
      imagePlaceholder: 'https://via.placeholder.com/200'
    }
      });
      
})

我尝试了几种方法,例如

$(function(){
    $('#summernote').summernote({

        callbacks: {
            onInit: function() {
                $(".cleaner").on('click', function (e) {
                    console.log('clicked');
                });
            }
        }
    
    });     
 })

但它什么也没做。

夏季笔记

评论


答: 暂无答案