jQUEry - 插入 内标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11953989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQUery - insert inside label
提问by Tony
I want to hide a label using the fadeOut
effect but when it is completed I want to insert inside it a
我想使用fadeOut
效果隐藏标签,但完成后我想在其中插入一个
$('label.alert').fadeOut('slow',function(){$(this).text(' ');});
but it produces a
as a raw text. Any ideas ?
但它产生一个
作为原始文本。有任何想法吗 ?
回答by fredrik
Use .html()
instead of .text()
.
使用.html()
代替.text()
。
回答by oboshto
Be careful with using .html()
or the same methods using another framework/library (e.g v-html
in Vue.js), because it has XSS vulnerability. Read more about XSS from this answer.
小心使用.html()
或使用另一个框架/库(例如v-html
在 Vue.js 中)的相同方法,因为它具有 XSS 漏洞。从这个答案中阅读更多关于 XSS 的信息。
Working way via .text():
You can simply replace
with \xa0
for text messages.
通过的.text()工作方式:
你可以简单地替换
用\xa0
短信提醒。
回答by Tony
replaceWith
did the trick
replaceWith
成功了
$('label.alert').fadeOut('slow',function(){$(this).replaceWith('<label class="alert"> </label>');});