jQuery $('id').text加粗 [英] jquery $('id').text with Bold
本文介绍了jQuery $('id').text加粗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个jQuery,它可以像这样更改链接的文本:
I have a jquery that changes the text of a link like so:
if (urlfind > 0) {
$('#linkurl').text('More info');
}
和html:
<a href = "" id = "linkurl"></a>
我试图在此链接中添加粗体,但是添加<b>More Info</b>
会使它们在文本本身中转义,而不是使文本变为粗体
I am trying to add bold to this link, but adding <b>More Info</b>
leaves them escaped in the text itself, rather than making the text bold
推荐答案
.html()
将字符串设置为HTML内容,而.text()
将字符串设置为文本.
.html()
sets string as HTML content, whereas .text()
sets the string as text.
写:
if (urlfind > 0) {
$('#linkurl').html('<b>More info</b>');
}
OR
if (urlfind > 0) {
$('#linkurl').html('<strong>More info</strong>');
}
这篇关于jQuery $('id').text加粗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文