我正在为元素添加属性,它具有样式。所以我能够在``内添加html标签。它有时工作,有时不工作。
工作时:
$('.card-text')
.text((size_avg).replace(/G/,'B'))
.attr({
'data-html': "true",
'data-original-title': `<strong><u>Size: </u></strong> Number of Subscribers, <strong>`+ addCommas(Math.round(size_avg)) + `</strong>`
});
结果是:
大小:订户数量,11.5
这很好
但是当我这样做时:
$('.card-text')
.text(Math.round(act_sub).replace(/G/,'B'))
.attr({
'data-html': "true",
'data-original-title': `<strong>yoyoyo</strong>`
});
结果如下:
<strong>yoyoyo</strong>
为什么我的代码第二次不起作用?
这很愚蠢,但是当我data-html="true"
在代码的HTML部分添加而不是将其添加到JS时,它就适用于第二个代码。
HTML代码:
<p class="card-text lg-metric-val" data-container="body" data-toggle="popover" data-placement="bottom" data-html="true">-</p>
并制作JS代码:
$('.card-text')
.text(Math.round(act_sub).replace(/G/,'B'))
.attr({'data-original-title': `<strong>yoyoyo</strong>`
});
它愚蠢,但正在工作。我不知道为什么它在代码的一部分而不是另一部分中作为jQuery属性传递。
谢谢大家!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句