简体   繁体   English

如何用逗号分隔$('ul li')。text

[英]How to separate $('ul li').text by comma

HTML HTML

<ul>
  <li>List 1</li>
  <li>List 2</li>
<ul>

jQuery jQuery的

$('ul li').text();

Current Output 电流输出

List1List2

Expected Output 预期产出

List1,List2

Question

How to separate them by comma? 如何用逗号分隔它们?

Try to use .map() along with .get() to get that texts into an array and .join() it afterwards, 尝试使用.map().get()将这些文本转换为数组,然后使用.join()

var values = $('#tags li').map(function(){ 
  return $(this).text(); 
}).get().join(','); // List1,List2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM