【问题标题】:How to find and replace text in CKEditor using Javascript?如何使用 Javascript 在 CKEditor 中查找和替换文本?
【发布时间】:2011-04-12 20:39:41
【问题描述】:

如何使用 Javascript 在 CKEditor 中查找和替换文本? 谢谢你的建议!

【问题讨论】:

    标签: javascript jquery jquery-selectors ckeditor


    【解决方案1】:

    试试这个

    editor = CKEDITOR.instances.fck; //fck is just my instance name you will need to replace that with yours
    
    var edata = editor.getData();
    
    var replaced_text = edata.replace("idontwant", "iwant this instead"); // you could also use a regex in the replace 
    
    editor.setData(replaced_text);
    

    你可能想把它放在模糊事件或其他东西中

    【讨论】:

    • @StanislasPiotrowski 查看此链接docs.ckeditor.com/#!/api/CKEDITOR.editor-event-change
    • @mcgrailm 我不想把它放在模糊事件中我想在条件下替换内容
    • @mcgrailm,这只是替换一个实例。如何替换所有实例。
    • @Abhijit 。你必须以某种方式创建一个循环来通过它们,所以你必须弄清楚你将如何定位它们。例如,给每个人一个类,然后以该类为目标并循环。这有意义吗。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-26
    • 2018-12-31
    • 2013-07-18
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    相关资源
    最近更新 更多