【问题标题】:how to add attribute name in summernote click to edit如何在summernote中添加属性名称点击编辑
【发布时间】:2017-02-18 12:36:23
【问题描述】:

我想在summernote中添加元素属性名点击编辑

html:

<button id="edit" class="btn btn-primary" onclick="edit()" type="button">Edit 1</button>
<button id="save" class="btn btn-primary" onclick="save()" type="button">Save 2</button>
<div class="click2edit">click2edit</div>

javascript:

var edit = function() {
  $('.click2edit').summernote({focus: true});
};

var save = function() {
  var makrup = $('.click2edit').summernote('code');
  $('.click2edit').summernote('destroy');
};

文档: http://summernote.org/examples/#click-to-edit

【问题讨论】:

  • 控制台有什么错误吗?
  • 没什么错误,我只是想在summernote编辑器中添加属性名,例如
  • 我了解您在寻找什么,请查看我的答案并尝试一下。 stackoverflow.com/a/39952607/6608101

标签: javascript jquery summernote


【解决方案1】:

你可以这样做。只需找到文本区域添加名称属性。希望它的工作。

var edit = function() {
    $('.click2edit').summernote({focus: true});
    $('.note-editor.note-frame.panel.panel-default').find('textarea').attr('name','mytextarea');
};

【讨论】:

  • 感谢 rupesh,我这样修改过,而且效果很好。 var edit = function() { $('.click2edit').summernote({focus: true}); $('.note-editor').find('textarea').attr('name','mytextarea'); };
  • 如果它对你有用。那么你可以纠正我的回答并增加我的回购。
【解决方案2】:

我认为你在这里不需要任何花哨的东西。

summernote selector 上使用attr()

$('.summernote').attr('name', 'content');

在这里,我假设$('.summernote') 是应用编辑器的选择器。

示例,展示如何获取编辑器实例

$("#id").on("summernote.init", function(e, layoutInfo) {
    // get $editor element 
    var $editor = layoutInfo.editor();

    // add id attribute in $editor element 
    $editor.attr('id', $(this).attr('id') + "-of-example");
}).summernote(
    // summernote options.. 
);

【讨论】:

    【解决方案3】:
    var edit = function() { 
      $('.click2edit').summernote({focus: true});
      $('.note-editor').find('textarea').attr('name','mytextarea');
    };
    

    【讨论】:

    • 虽然这段代码 sn-p 可以解决问题,但including an explanation 确实有助于提高帖子的质量。请记住,您是在为将来的读者回答问题,而这些人可能不知道您提出代码建议的原因。
    猜你喜欢
    • 2017-12-07
    • 2018-12-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 2017-04-23
    • 2021-09-22
    • 2016-02-14
    • 1970-01-01
    相关资源
    最近更新 更多