Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用jQuery从下表获取{id:value}对并高效地复制到另一个具有相同结构的表? 公司作业标题行业作业功能开始日期结束日期_Jquery_Input - Fatal编程技术网

如何使用jQuery从下表获取{id:value}对并高效地复制到另一个具有相同结构的表? 公司作业标题行业作业功能开始日期结束日期

如何使用jQuery从下表获取{id:value}对并高效地复制到另一个具有相同结构的表? 公司作业标题行业作业功能开始日期结束日期,jquery,input,Jquery,Input,这是另一张表: <table id="experiences" cellpadding="0" border="1" width="100%" height="100%"> <tr><th>Company</th><th>Job Title</th><th>Industry</th><th>Job Function</th><th>Start Date</t

这是另一张表:

<table id="experiences" cellpadding="0" border="1" width="100%" height="100%">

<tr><th>Company</th><th>Job Title</th><th>Industry</th><th>Job Function</th><th>Start Date</th><th>End Date</th></tr>
<tr>
    <td><input type="text" name="company1" class="w100" /></td><td><input type="text" name="jobTitle1" class="w100" value="" /></td><td><input type="text" name="industry1" class="w100" value="" /></td><td><input type="text" name="jobFunction1" class="w100" /></td><td><input type="text" name="startDateJob1" class="w100" /></td><td><input type="text" name="endDateJob1" class="w100" /></td>
</tr>
<tr>
    <td><input type="text" name="company2" class="w100" /></td><td><input type="text" name="jobTitle2" class="w100" /></td><td><input type="text" name="industry2" class="w100" /></td><td><input type="text" name="jobFunction2" class="w100" /></td><td><input type="text" name="startDateJob2" class="w100" /></td><td><input type="text" name="endDateJob2" class="w100" /></td>
</tr>
<tr>
    <td><input type="text" name="company3" class="w100" /></td><td><input type="text" name="jobTitle3" class="w100" /></td><td><input type="text" name="industry3" class="w100" /></td><td><input type="text" name="jobFunction3" class="w100" /></td><td><input type="text" name="startDateJob3" class="w100" /></td><td><input type="text" name="endDateJob3" class="w100" /></td>
</tr>
<tr>
    <td><input type="text" name="company4" class="w100" /></td><td><input type="text" name="jobTitle4" class="w100" /></td><td><input type="text" name="industry4" class="w100" /></td><td><input type="text" name="jobFunction4" class="w100" /></td><td><input type="text" name="startDateJob4" class="w100" /></td><td><input type="text" name="endDateJob4" class="w100" /></td>
</tr>

</table>

公司作业标题行业作业功能开始日期结束日期
至于复制值,这应该是可行的

var obj = {};
$('#experiences input').each(function () {
    obj[$(this).attr('name')] = $(this).val();
});

一种选择是克隆表

下面克隆表,更改id并附加到someContainer

// clone original table
var tab = $('#experiences').clone();

// change the id
tab.attr('id', 'experiences-mirror');

// replace inputs with corresponding values
tab.find('input').each(function() {
    var elem = $(this);
    elem.remove();
    elem.parent().text(elem.val());
});

// replace empty tab with filled one
$('#experiences-mirror').replaceWith(tab);

请参阅jquery文档中的帮助

@RaYell,我已更改了我的问题。很抱歉延迟。@RaYell,当某些表更改为时,如何使其也适用于will选项卡。find('input | select')起作用?不,第一个表包含在其单元格中,而第二个表包含纯文本。因此,您的代码将不起作用,是吗?那么你的问题就错了,就像你说的一样,是吗:)得了吧,找到输入,把值放到单元格里,然后去掉输入有多难……减少样本是有意义的。
// clone original table
var tab = $('#experiences').clone();

// change the id
tab.attr('id', 'experiences-mirror');

// replace inputs with corresponding values
tab.find('input').each(function() {
    var elem = $(this);
    elem.remove();
    elem.parent().text(elem.val());
});

// replace empty tab with filled one
$('#experiences-mirror').replaceWith(tab);
$('#experiences').clone()
                 .attr('id', 'experiences-mirror')
                 .appendTo('#someContainer');