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

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。
发布于 2016-12-28 17:35:55
就像我说的,我不知道顶点,但我有个大致的想法:
一旦您能够获得所选的复选框,您需要在每个复选框与他的后续输入之间建立一个关系:因此,您需要为每个复选框提供一个唯一的id :如下所示:
<input type="checkbox" data-inputid="val1">
<input type="text" id="val1">
<input type="checkbox" data-inputid="val2">
<input type="text" id="val2"> 然后,您可以使用
数据输入d
要设置值,请执行以下操作:
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',因此值被复制到任何地方都是正常的。
希望有此帮助:)
https://stackoverflow.com/questions/41365739
复制相似问题