我正在通过java脚本设置h4的文本我想要做的是在这里添加新行代码
$("#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");
任何帮助?
答案 0 :(得分:6)
尝试使用$("#description").html(...)
代替$("#description").text(...)
。
答案 1 :(得分:3)
使用 html 代替 text 。这是因为 html 将呈现HTML代码。 text 方法仅插入和转义所有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);
});
&#13;
<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>
&#13;
答案 2 :(得分: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.");
答案 3 :(得分:2)
使用html函数
tag.it will preserve your raw html .
viewPager.setCurrentItem(pageNumber);