首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用其他字段值设置表的选中字段值

用其他字段值设置表的选中字段值
EN

Stack Overflow用户
提问于 2016-12-28 16:09:03
回答 1查看 716关注 0票数 0

我在jQuery遇到了一些麻烦。表中有一些行,其中有3列(复选框、名称、金额),在表的上方也有一个字段。在这里,我希望将此字段的值复制到选中复选框的amount字段中。在屏幕截图中,我希望将黄色的值放到表的选中字段中。

代码语言:javascript
复制
        Assign Quota to Sales : 
    <apex:inputText id="ValueToCopy" value="{!ForecastingQuota.QuotaAmount}" required="false">
</apex:inputText>
<apex:commandButton value="Assign to Selected Users" reRender="allquotas" onclick="copyQuotaAmount();"/>

<apex:pageBlockSection columns="4" id="allquotas">
<apex:pageBlockTable value="{!allthequotas}" id="table" var="key">
<apex:facet name="header">
<input type="checkbox" id="checkAllBox" onchange="toggleCheckAll(this)"/> Select All
</apex:facet>
<apex:column>
<apex:inputCheckbox styleClass="selectInput"/>
</apex:column>
<apex:column headerValue="Name">
<apex:outputField  value="{!key.QuotaOwnerId}"/>
</apex:column>
<apex:column headerValue="Quota">
<apex:inputField value="{!key.QuotaAmount}" required="false" id="test"/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockTable value="{!allthequotas2}" var="key2">
<apex:facet name="header">
<input type="checkbox" id="checkAllBox2" onchange="toggleCheckAll2(this)"/> Select All
</apex:facet>
<apex:column>
<apex:inputCheckbox styleClass="selectInput2"/>
</apex:column>
<apex:column headerValue="Name">
<apex:outputField  value="{!key2.QuotaOwnerId}"/>
</apex:column>
<apex:column headerValue="Quota">
<apex:inputField value="{!key2.QuotaAmount}" required="false" id="test"/>
</apex:column>
</apex:pageBlockTable> 
<apex:pageBlockTable value="{!allthequotas3}" var="key3">
<apex:facet name="header">
<input type="checkbox" id="checkAllBox3" onchange="toggleCheckAll3(this)"/> Select All
</apex:facet>
<apex:column>
<apex:inputCheckbox styleClass="selectInput3"/>
</apex:column>
<apex:column headerValue="Name">
<apex:outputField  value="{!key3.QuotaOwnerId}"/>
</apex:column>
<apex:column headerValue="Quota">
<apex:inputField value="{!key3.QuotaAmount}" required="false" id="test"/>
</apex:column>
</apex:pageBlockTable> 
<apex:pageBlockTable value="{!allthequotas4}" var="key4">
<apex:facet name="header">
<input type="checkbox" id="checkAllBox4" onchange="toggleCheckAll4(this)"/> Select All
</apex:facet>
<apex:column>
<input type="checkbox" styleClass="selectInput4"/>
</apex:column>
<apex:column headerValue="Name">
<apex:outputField  value="{!key4.QuotaOwnerId}"/>
</apex:column>
<apex:column headerValue="Quota">
<apex:inputField value="{!key4.QuotaAmount}" required="false" id="test"/>
</apex:column>
</apex:pageBlockTable> 
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>

<script type="text/javascript">
 function copyQuotaAmount()
    {
        $("input[type=checkbox][checked]").each(function(){
                $("input[id$='test']").val($("input[id$='ValueToCopy']").val());
                });
    }

我已经试过了,但我不知道如何在选定的领域。

谢了Dev。

HTML

EN

回答 1

Stack Overflow用户

发布于 2016-12-28 17:35:55

就像我说的,我不知道顶点,但我有个大致的想法:

一旦您能够获得所选的复选框,您需要在每个复选框与他的后续输入之间建立一个关系:因此,您需要为每个复选框提供一个唯一的id :如下所示:

代码语言:javascript
复制
<input type="checkbox" data-inputid="val1">
<input type="text" id="val1"> 
<input type="checkbox" data-inputid="val2">
<input type="text" id="val2"> 

然后,您可以使用

数据输入d

要设置值,请执行以下操作:

代码语言:javascript
复制
function copyQuotaAmount()
    {
        $("input[type=checkbox]:checked").each(function(){
            // $(this) refers to the current checked box in loop
            var inputid = $(this).data('inputid');
            var valuetocopy = $('#ValueToCopy').val();
            // if you can force the id of the input field to a specific value then use this
            $('#' + inputid).val(valuetocopy);
            // else if you can't force the value (then based on your html output), you must use this
            $("input[type='text'][id$='" + inputid + "']").val(valuetocopy)

        });
    } 

因此,即使您获得所选的复选框,也是在选中的元素上循环,但随后使用id="test"选择所有字段,而且由于所有输入都有id='test',因此值被复制到任何地方都是正常的。

希望有此帮助:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41365739

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档