Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个页面,其中有多个跨度标签应用了相同的 css 类。我想获取所有这些跨度标签的文本。我用 $('.clsname').text(); 但问题是,它将所有跨度标签文本作为单个字符串返回。我需要它到一个数组/分隔
提前致谢
尝试这个:
var text = []; $('.clsname').each(function(){ text.push( $(this).text()); });
.each()迭代所有选定的元素。
.each()
var arr = []; $('.clsname').each(function(){ arr.push($(this).text()); });