簡體   English   中英

替換ckeditor中的內容標簽html

[英]Replace content tag html in ckeditor

我通過命令在ckeditor中獲取內容

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

而且我收到了像<h3 class="Interview">any word(may be unicode)</h3>這樣的字符串,如何用javascript替換為<h3 class="Interview">My word</h3> ? ?

請幫我 !!! 謝謝 !!!

這應該工作

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

您可以使用regexp來做到這一點:

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

嘗試這個:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM