jQuery 如何清除 <label> 的文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7986996/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 00:34:04  来源:igfitidea点击:

How to clear a <label>'s text

jquery

提问by PositiveGuy

Trying to figure out how to clear my label's text...clear it out. So far no luck:

试图弄清楚如何清除我的标签文本...清除它。到目前为止没有运气:

$("label[id*=\"singleModelText\"]").text().empty();

回答by mccow002

Try

尝试

$('label[id*="singleModelText"]').text('');

回答by Kai Qing

Or if .text('') doesn't work

或者如果 .text('') 不起作用

$('label[id*=singleModelText').html('');

but if there's an id why not just do this:

但如果有一个 id 为什么不这样做:

$('#singleModelText').html('');

回答by Vikas Naranje

Try with

试试

   $('label[id*=singleModelText]').empty();

OR

或者

   $('label[id*=singleModelText]').text('');

回答by Feisty Mango

$('label[id*="singleModelText"]').text('')

Keep in mind that there is a simpler id selector of $('#ID')assuming you have the full id and not just a partial id

请记住,有一个更简单的 id 选择器,$('#ID')假设您拥有完整的 id 而不仅仅是部分 id

Here is a JS Fiddle

这是一个 JS 小提琴

http://jsfiddle.net/QFseE/

http://jsfiddle.net/QFseE/

回答by Sohail Asghar

Try this:

尝试这个:

$('label[id*="singleModelText"]').empty();