2017-06-05 53 views
1

我設置通過Java腳本H4是我想要做的文本添加新行這裏的如何打破行Java腳本

$("#description").text("for CCAET and has received significant international scientific recognition. <br /> \n Dr. Armogan has also been responsible for many surgical firsts in retina and cataract management."); 

現在我有多個解決方案,但還沒有嘗試過的代碼在這裏工作的另一個

$("#description").text("or CCAET and has received significant international scientific recognition.Dr. Armogan has also been responsible for many surgical firsts in retina and cataract management."+ 
         "abc"+ 
         "def"); 

任何幫助嗎?

回答

6

嘗試$("#description").html(...)而不是$("#description").text(...)

+2

和'
'用於線打破 –

+0

現在工作在JavaScript中,它顯示
,因爲它是 –

+1

完美的男人!謝謝... :) –

3

使用html而不是文本。這是因爲html將呈現HTML代碼。 文本方法將只插入和轉義所有HTML內容。參考。 https://api.jquery.com/html/

$(document).ready(function() { 
 

 
    var content = "This<br/>is<br/>modified<br/>text"; 
 

 
    $('h4#one').html(content); 
 
    $('h4#two').text(content); 
 

 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
 

 
<h4 id="one"> 
 
    This is initial text 
 
</h4> 
 

 
<h4 id="two"> 
 
    This is initial text 
 
</h4>

2

使用HTML()函數把原始HTML的元件內作爲

$("#description").html("for CCAET and has received significant international scientific recognition. <br /> \n Dr. Armogan has also been responsible for many surgical firsts in retina and cataract management."); 
2

使用HTML功能與

 tag.it will preserve your raw html .

$("#description").html("<pre>for CCAET and has received significant international scientific recognition. <br /> \n Dr. Armogan has also been responsible for many surgical firsts in retina and cataract management.</pre>");