2016-07-18 1 views
0

brタグがDIVで機能していません。 更新内容:textareaフィールドからメッセージが届きます。 メッセージには、 "Rama"の次の行 "Lingam"のような2行があります。 結果は "Rama
Lingam" by $("#editQuotesRowLabel_Q_013").text(replaceContent);brタグが機能していないときに、JREERYテキスト関数を使用してテキストエリアからDIVにコンテンツを置き換えます。

DIVで新しい行を作るには?ここで

は私のコードです:

function updateQuotes(){  
    var weg_quotes = $("#weg_quotes_Q_013").val(); 
    replaceContent = weg_quotes.replace("\n", "<br>", "g");   
    $("#editQuotesRowLabel_Q_013").text(replaceContent); 
} 
Update Content: <textarea placeholder="Update your content..." id="weg_quotes_Q_013" name="weg_quotes" cols="80" rows="3" class="appQuotesTextarea" maxlength="200" required=""></textarea> 
<button onclick="updateQuotes()" id="Q_013" name="update-btn" class="appQuotesBtn">Update</button> 

<div id="editQuotesRowLabel_Q_013" class="appQuotesLabel"> 
    This is content div. 
</div> 

答えて

3

あなたが.html()代わりの.text()を使用する必要がjqueryのを使用してHTMLコンテンツを挿入します。 は、だからあなたの場合には、あなたがで終わる:

$("#editQuotesRowLabel_Q_013").html(replaceContent); 
//        |_ use html() instead of text() 

出典:テキストエリアの内容も
タグが含まれていますので、

+0

これはうまく働いています。ありがとうございます! –

2

ちょうど.html()の代わり.text()を使用.html()はhtmlを表示することもできます。.text()は、テキストのみを考慮します - それは私がそのreplace()メソッドが何であるかわからないのdivに(ここでは
タグを)htmlタグを設定し、その.html()代わりの.text()

function updateQuotes(obj){ 
 
    var weg_quotes = $("#weg_quotes_Q_013").val(); 
 
    replaceContent = weg_quotes.replace("\n", "<br>", "g"); 
 
    $("#editQuotesRowLabel_Q_013").html(replaceContent); 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> 
 
Update Content: <textarea placeholder="Update your content..." id="weg_quotes_Q_013" name="weg_quotes" cols="80" rows="3" class="appQuotesTextarea" maxlength="200" required=""></textarea> 
 
<button onclick="updateQuotes(this)" id="Q_013" name="update-btn" class="appQuotesBtn">Update</button> 
 

 
<div id="editQuotesRowLabel_Q_013" class="appQuotesLabel"> 
 
    This is content div. 
 
</div>

+0

それはうまく働いています。ありがとうございます! –

1

を使用することはありませんが、それは交換するので、あなたのコードが

でなければなりません

str.replace(pattern/string, function/replacement) 

です

divにhtmlを挿入する場合は、.html()を使用する必要があります。

$("#editQuotesRowLabel_Q_013").html(replaceContent); 
+0

これはうまく働いています。ありがとうございます! –

+0

@RamaLingam FYI、あなたがreplace()行を変更することについて私のアドバイスに従ってくれたらうれしく思います。あなたが2つ持っていれば、他のすべての答えは失敗するでしょう。 – epascarello

2

これを試してみてください:

$("#editQuotesRowLabel_Q_013").html(replaceContent); 

//代わりにtext()

html()を使用してみてください。これは、あなたがhtmlタグを使用できるようになります:)

1

はこの1 .html()を試してみてください.text()

の代わりに
$("#editQuotesRowLabel_Q_013").html(replaceContent); 
関連する問題