2017-06-05 38 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>");