[英]Why is my `` working sometimes and not others?
I am adding attributes to element and it has styling to it.我正在向元素添加属性,并且它具有样式。 So I was able to add the html tags inside of ``.
所以我能够在 `` 中添加 html 标签。 It is working sometimes and sometimes not.
它有时有效,有时无效。
When it is working:当它工作时:
$('.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>`
});
The result for this is:这样做的结果是:
Size: Number of Subscribers, 11.5规模:订阅者数量, 11.5
This works fine这工作正常
But when I do this:但是当我这样做时:
$('.card-text')
.text(Math.round(act_sub).replace(/G/,'B'))
.attr({
'data-html': "true",
'data-original-title': `<strong>yoyoyo</strong>`
});
The result for this:这样做的结果:
<strong>yoyoyo</strong>
Why is my code not working at the second time?为什么我的代码在第二次不起作用?
This is silly, but it is working for the second one when I add data-html="true"
at the HTML part of the code instead of adding it to the JS. 这很愚蠢,但是当我在代码的HTML部分添加
data-html="true"
而不是将其添加到JS时,它适用于第二个代码。
HTML Code: HTML代码:
<p class="card-text lg-metric-val" data-container="body" data-toggle="popover" data-placement="bottom" data-html="true">-</p>
And make the JS code: 并制作JS代码:
$('.card-text')
.text(Math.round(act_sub).replace(/G/,'B'))
.attr({'data-original-title': `<strong>yoyoyo</strong>`
});
Its dumb but it is working. 它愚蠢,但正在工作。 I don't know why it was working passing it as a jQuery attribute in one part of the code and not the other.
我不知道为什么它在代码的一部分而不是另一部分中将它作为jQuery属性传递。
Thank you everyone! 谢谢大家!
I am not sure that the ` type of ticks should work at all. 我不确定滴答声的类型是否应该起作用。 I think you have discovered a quirk, and I don't think you should expect consistent behaviour from using a quirk;
我认为您已经发现了一个怪癖,并且我认为您不应期望通过使用怪癖而获得一致的行为。 ie, it may only be working by accident, and the code that executes inside the interpreter (be it a browser, or otherwise) might not ever be tested for use with the ` character.
也就是说,它可能只是偶然地起作用,并且可能永远不会测试在解释器(无论是浏览器还是其他方式)内部执行的代码是否可以与`字符一起使用。
Replace all the ` with a " , and see how it behaves. 将所有`替换为“,然后查看其行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.