我可以用这个正则表达式换个词,
editor = CKEDITOR.instances.txtisi;
var edata = editor.getData();
var rep_text = edata.replace("INSERT INTO", "INSERT-INTO");
editor.setData(rep_text);但是,如何增加更多的单词,将取代,而不仅仅是一个词。我已经试过了,但我总是得到最后的答案。如this.editor = CKEDITOR.instances.txtisi;
var edata = editor.getData();
var rep_text = edata.replace("INSERT INTO", "INSERT-INTO"); // you could also
var rep_text = edata.replace("DELETE TABLE", "DELETE-TABLE"); // you could also
var rep_text = edata.replace("TRUNCATE TABLE", "TRUNCATE-TABLE"); // you could also use a regex in the replace
editor.setData(rep_text);发布于 2015-07-13 06:46:47
您的代码中有一个bug。
这是固定版本
var edata = editor.getData();
var edata = edata.replace("INSERT INTO", "INSERT-INTO"); // you could also
var edata = edata.replace("DELETE TABLE", "DELETE-TABLE"); // you could also
var edata = edata.replace("TRUNCATE TABLE", "TRUNCATE-TABLE"); // you could also use a regex in the replace
editor.setData(edata);原因是string.replace()返回一个新字符串,而旧字符串不受影响。(就像任何字符串操作一样)。因此,您需要在每次调用edata之后使用新的数据更新.replace()变量。
https://stackoverflow.com/questions/31375690
复制相似问题