doubeng3216 2017-03-23 05:49
浏览 283
已采纳

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

I fetch the records from form(i.e from dynamic table) and trying to store in variable, but face a problem that both values are not separated by comma so trouble to store that values. Here is my code:

 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();

if my table contains two rows like, 1. java and 2. html so when I store it into variable skill_f, I got value as javahtml, and importance as MandetoryOptional so I facing problem while storing these two value, so what should i do? How to separate them? How to store values?

and Like skills parameter, there are other parameters too.

  • 写回答

1条回答 默认 最新

  • dsvs50005 2017-03-23 06:05
    关注

    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>

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?