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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度