将列的值复制到另一列

时间:2017-09-14 09:42:48

标签: jquery sharepoint-2013

在SharePoint 2013列表中,有多行文本列A,并且还有另一行多行文本列B.我希望仅在项目编辑时将文本从列B复制到列A,因此在编辑表单中。

我以为我会尽快完成,但我无法解决 我试过的是

$(document).ready(function(){
        $("#columnA").val($("#columnB").val()); 
});

EDIT
编辑表单页面的一部分,我在其中添加了ID

<table border="0" cellspacing="0" width="100%">
    <tr>
        <td width="190px" valign="top" class="ms-formlabel">
          <H3 class="ms-standardheader">
            <nobr>A</nobr>
          </H3>
        </td>
        <td width="400px" valign="top" class="ms-formbody" id="columnA">
         <SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="Edit" FieldName="A" __designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@A')}"/>
         <SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="A" ControlMode="Edit"/>
        </td>
    </tr>
    <tr>
    <td width="190px" valign="top" class="ms-formlabel">
        <H3 class="ms-standardheader">
          <nobr>B</nobr>
        </H3>
    </td>
    <td width="400px" valign="top" class="ms-formbody" id="columnB">
      <SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="Edit" FieldName="B" __designer:bind="{ddwrt:DataBind('u',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@B')}"/>
      <SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="B" ControlMode="Edit"/>
     </td>
    </tr>
</table>

4 个答案:

答案 0 :(得分:1)

&#39;列A&#39;和&#39; columnB&#39;在不同的行? 你想设置&#39; columnB&#39;来自前行&#39;列A&#39;的值,并循环显示?

$(document).ready(function(){
  $('tr:has(columnA)').each(function(this){
    var aVal = $(this).find('columnA').html();
    $(this).next().find('columnB').html(aVal);
  });
});

上面的代码是你想要的吗?

答案 1 :(得分:0)

这里有一个关于如何使用jQuery each解决问题的方法。

https://jsfiddle.net/pyn20ogc/

@Dalton的方法不同但相似,可能更好。

答案 2 :(得分:0)

另一种基于@TKoL示例的方法:

&#13;
&#13;
$('#run').click(function() {
    $('tr td').each(function() {
        var value = $(this).text()
        $(this).next().html(value)
    })
})
&#13;
table td {
  border: solid 1px #ccc;
  min-width: 40px;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
  <td class="first">a</td>
  <td class="second"></td>
</tr>
<tr>
  <td class="first">b</td>
  <td class="second"></td>
</tr>
<tr>
  <td class="first">c</td>
  <td class="second"></td>
</tr>
</table>
<br>
<button id="run">Copy</button>
&#13;
&#13;
&#13;

答案 3 :(得分:0)

我解决了类似于我问的问题,但是我把DIV的ID代替了TD。

$(document).ready(function(){
   $("#.._TextField_inplacerte").text($("#.._TextField_inplacerte").text());
});