2015-07-13 38 views
0

我可以改变CKEditor的一个词与此正则表达式,ckeditor替换字怎么添加更多?

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); 

回答

1

。在你的代码

的错误这是固定的版本

 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()

+0

谢谢,解决:) –