javascript 使用 jQuery 获取标签内的值。?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7258334/
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-10-25 23:28:52 来源:igfitidea点击:
get value of inside a tag with jQuery.?
提问by Kate Thompson
How can by jQuery get value inside tag b
?
jQuery 如何获取标签内的值b
?
<span>
<b>hi_1</b>
<b>hi_2</b>
<b>hi_3</b>
<b>hi_4</b>
<span>
I want this output with jQuery: hi_1, hi_2, hi_3, hi_4
我想要这个带有 jQuery 的输出: hi_1, hi_2, hi_3, hi_4
Please give me example in jsfiddle.
请给我jsfiddle 的例子。
回答by JaredPar
回答by ShankarSangoli
Are you looking for something like this?
你在寻找这样的东西吗?
$(document).ready(function() {
var textArr = [];
$('span b').each(function() {
textArr.push($(this).text());
});
alert(textArr.join(', '));
});
回答by mplungjan
This is cool
这很酷
var x = $("span b").map(function() {
return $(this).text();
}).toArray().join(", ");