2012-11-14 34 views
2

內容標記HTML我的命令替換CKEditor的

var content = $('#editor1').val(); // With editor1 is my ckeditor

獲得內容的CKEditor我收到這樣<h3 class="Interview">any word(may be unicode)</h3> 字符串我怎樣才能通過它的JavaScript來代替???? <h3 class="Interview">My word</h3>

請幫幫我!!!謝謝 !!!

回答

0

這應該工作

result = subject.replace(/(<[a-z][a-z0-9]*[^<>]*>)([a-z][a-z0-9]*[^<>]*)(<\/?[a-z][a-z0-9]*[^<>]*>)/, "$1 My words $3"); 
0

您可以通過使用正則表達式:

var a = '<h3 class="Interview">any word(may be unicode)</h3>' 
a = a.replace(/(<h3[^>]*>)[^<]*<\/h3>/g, '$1'+'your words</h3>') 
0

試試這個:

var str="<h3 class=\"Interview\">any word(may be unicode)</h3>"; 

function htmlTextReplace(original){ 
    var regex = />([^<]*)</g; 
    return original.replace(regex, function($0, $1){ 
     return $0.replace($1, strTextReplace($1, 'any word','your words')); 
    }); 
} 

function strTextReplace(str, ow, dw){ 
    return str.replace(ow, dw); 
} 
console.log(htmlTextReplace(str));