当我点击按钮并添加带有summernote和自定义按钮的课程时,如何获取所选文本。
var HelloButton = function (context) {
var ui = $.summernote.ui;
// create button
var button = ui.button({
contents: '<i class="fa fa-child"/> Hello',
tooltip: 'hello',
click: function (event) {
// Here my selected text
value = "My selected text";
// Here add balise and class
value = '<h1 class="myClass">+value+</h1>';
// Here modify textarea
context.invoke('editor.insertText', value);
}
});
return button.render(); // return button as jquery object
}
答案 0 :(得分:-1)
将点击更改为:
click: function() {
var text = context.invoke('editor.getSelectedText'); // HERE IS YOUR SELECTED TEXT
var $node = $('<h1 class="YOUR_CLASS">'+text+'<h1>');
context.invoke('editor.insertNode', $node[0]);
}