[英]Get the value from SCEditor
我正在尝试使用以下代码从我的 SCEditor 文本区域获取值:
var fbeschreibung = '';
$(function() {
// Replace all textarea's
// with SCEditor
$("textarea").sceditor({
plugins: "bbcode",
style: "css/style.less",
width: "100%",
toolbar:"bold,italic,underline,strike,subscript,superscript|left,center,right,justify|size,color,removeformat|bulletlist,orderedlist,horizontalrule,emoticon",
locale:"de" ,
resizeEnabled:false
});
fbeschreibung = $('textarea').sceditor('instance').val();
$('textarea').sceditor('instance').val('Hello [b]World![/b]');
});
然后我想通过 AJAX 发送值:
$.post('saveprofile.php',
{fbeschreibung : fbeschreibung},
function (response) {
alert(response);
}
);
但是,我无法让它发挥作用。 我还没有在文档中找到任何提示: http : //www.sceditor.com/api/sceditor/val/
我的变量fbeschreibung
只是空的。 我做错了什么吗?
这对我有用:
$(function() {
// Replace all textarea's
// with SCEditor
var fbeschreibung = $("textarea").sceditor({
plugins: "bbcode",
style: "css/style.less",
width: "100%",
toolbar:"bold,italic,underline,strike,subscript,superscript|left,center,right,justify|size,color,removeformat|bulletlist,orderedlist,horizontalrule,emoticon",
locale:"de" ,
resizeEnabled:false
}).sceditor('instance');
var value = fbeschreibung.getBody().html();
});
我不熟悉这个特定的编辑器,但我提供给你的选项(评论)可能有用。
var fbeschreibung = '';
$(function() {
// Replace all textarea's
// with SCEditor
var editor = $("textarea").sceditor({
plugins: "bbcode",
style: "css/style.less",
width: "100%",
toolbar:"bold,italic,underline,strike,subscript,superscript|left,center,right,justify|size,color,removeformat|bulletlist,orderedlist,horizontalrule,emoticon",
locale:"de" ,
resizeEnabled:false
});
/* Try the following 3 options */
fbeschreibung = editor.val();
fbeschreibung = editor.getSourceEditorValue();
fbeschreibung = editor.getWysiwygEditorValue();
editor.val('Hello [b]World![/b]');
});
我在使用 JQuery 代码时遇到了一些问题,发现实际上可以在不使用 JQuery 的情况下使用:
sceditor.instance(textarea).val()
其中textarea
是您的编辑器创建的 textarea :
let textarea = document.getElementById('my-textarea');
// the sceditor variable is created by importing the sceditor JavaScript code
// (sceditor.min.js and formats/bbcode.js)
sceditor.create(textarea, {
format: 'bbcode',
style: '/minified/themes/content/default.min.css'
});
function logEditorValue(){
let textarea = document.getElementById('my-textarea');
let value = sceditor.instance(textarea).val();
console.log(value); // prints the value of the sceditor
}
如果页面上有多个 SCEditor,则可以使用将不同的textarea
传递给sceditor.instance
函数
(有关SCEditor GitHub上“使用”部分的更多信息)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.