{blank}テキストを入力ボックスに置き換えようとしますが、{blank}テキストを入力ボックスに置き換えます。あなたはプレーンな文字列ではなく、正規表現を使用したいと思う入力ボックスにmultipal {blank}テキストを置き換えます。
var r= '{blank}';
var re = new RegExp(r, 'g');
$this.html($this.html().replace(re, '<input type="text"/>'));
{blank}テキストを入力ボックスに置き換えようとしますが、{blank}テキストを入力ボックスに置き換えます。あなたはプレーンな文字列ではなく、正規表現を使用したいと思う入力ボックスにmultipal {blank}テキストを置き換えます。
var r= '{blank}';
var re = new RegExp(r, 'g');
$this.html($this.html().replace(re, '<input type="text"/>'));
使用正規表現のためのコードです。これは動作します
$this.html($this.html().replace(/{blank}/g,'<input type="text">'));
理由は、プレーンな文字列は一度だけ一致していることですが、グローバルフラグ付き正規表現は、すべてのインスタンスと一致します(つまり、末尾の「G」であるものです)。
:下記の文字列にグローバルマッチのために設定されg
フラグをrefrence
$(".editer-save .btn-primary").click(function(){
$("#editor").each(function(){
$this = $(this);
$this.html($this.html().replace('{blank}','<input type="text">'));
$('#editorPreview').show().html($('#editor').cleanHtml());
});
});