用内容字符串 Javascript 预填充 Summernote

Pre-fill Summernote with content string Javascript

我有一个 Summernote 所见即所得,其中的内容必须预先填充已经从另一个 Summernote 实例中提取的字符串中的内容。

$("#summernote").summernote("code", 'This is thing's content from anither instance');

当字符串中有引号字符时会出现问题,这会过早地打破字符串的范围(单词 thing's 中的 ')。

还有其他方法吗?

我想到的唯一其他方法是在将其设置为将文本加载到编辑器的函数之前删除 ' 字符。

使用'\'转义麻烦的字符,例如:

$("#summernote").summernote("code", "This is thing\'s content from anither instance");

或者如果它是预填充的,则用 str_replace:

解析它
$("#summernote").summernote("code", str_replace("'", "\'", str));