我通过命令在 ckeditor 中获取内容
var content = $('#editor1').val(); // With editor1 is my ckeditor
我收到一个字符串,比如<h3 class="Interview">any word(may be unicode)</h3>
我如何<h3 class="Interview">My word</h3>
用 javascript 替换它????
请帮我 !!!谢谢 !!!
我通过命令在 ckeditor 中获取内容
var content = $('#editor1').val(); // With editor1 is my ckeditor
我收到一个字符串,比如<h3 class="Interview">any word(may be unicode)</h3>
我如何<h3 class="Interview">My word</h3>
用 javascript 替换它????
请帮我 !!!谢谢 !!!
尝试这个:
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));
这应该工作
result = subject.replace(/(<[a-z][a-z0-9]*[^<>]*>)([a-z][a-z0-9]*[^<>]*)(<\/?[a-z][a-z0-9]*[^<>]*>)/, "$1 My words $3");
您可以通过使用正则表达式来做到这一点:
var a = '<h3 class="Interview">any word(may be unicode)</h3>'
a = a.replace(/(<h3[^>]*>)[^<]*<\/h3>/g, '$1'+'your words</h3>')