繁体   English   中英

从表格中获取数据时如何用逗号分隔多个值

[英]how to separate multiple values with comma while fetching from form

我从表单(即从动态表)中获取记录,并尝试存储在变量中,但是遇到一个问题,即两个值都不用逗号分隔,因此难以存储该值。 这是我的代码:

 var skill_f = $("#table_display_skills tr").find('td:nth-child(1)').text().trim();
 var importanceSkill_f = $("#table_display_skills tr").find('td:nth-child(2)').text().trim();

 var industry_f = $("#table_display_industry tr").find('td:nth-child(1)').text().trim();
 var importanceIndustry_f = $("#table_display_industry tr").find('td:nth-child(2)').text().trim();

 var education_f = $("#table_display_education tr").find('td:nth-child(1)').text().trim();
 var importanceEducation_f = $("#table_display_education tr").find('td:nth-child(2)').text().trim();

如果我的表包含两行,例如1. java和2. html,那么当我将其存储到变量skill_f中时,我得到的值为javahtml ,重要性为MandetoryOptional,因此在存储这两个值时遇到问题,那么我该怎么办? 如何将它们分开? 如何储存价值?

像技能参数一样,还有其他参数。

 var joinSkill = (elements) => { var skills = []; elements.each(function() { skills.push($(this).text().trim()); }); return skills.join(','); }; var skill_f = joinSkill($("#table_display_skills tr > td:first-child")); console.log(skill_f); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table id="table_display_skills"> <tr> <td>css</td> <td>css2</td> </tr> <tr> <td>html</td> <td>html2</td> </tr> </table> 

暂无
暂无

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

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