我創建了一個受益人窗體,當用戶選擇受益人時,窗體會自動填充指定的百分比。例如,用戶可以選擇子1,並根據他們爲另一個表中的子1指定的百分比份額,自動填充此形式的百分比(函數beneficiary_1())。我會爲每個百分比字段來總結所有的百分比的一個獨立的onChange腳本,但我不認爲它的工作原理與自動填充字段...onChange不適用於自動填充字段
function percentSum(){
var arr = document.getElementsByName('beneficiary_share');
var tot=0;
for(var i=0;i<arr.length;i++){
if(parseInt(arr[i].value))
tot += parseInt(arr[i].value);
}
document.getElementById('total_percentage').value = tot;
}
有沒有一種方法,我可以修改此所以它適用於自動填充字段?
HTML:
<tr>
<td style="border-right: 1px solid #000000;">
<g:ui_reference name="family_member_1" id="family_member_1" table="hr_beneficiary" query = "active=true^employee=javascript:gs.getUserID()" completer="AJAXTableCompleter" columns="employee; beneficiary_contact.relationship" onChange="beneficiary_1()" />
</td>
<td class = "inside"><input class = "sf2823" type="text" id="fm1_ssn" name ="fm1_ssn" style="background-color:#dddddd" readonly="readonly"/>
</td>
<td class = "inside"><input class = "sf2823" type="text" id="fm1_address" name ="fm1_address" style="background-color:#dddddd" value="" readonly="readonly"/>
</td>
<td class = "inside"><input class = "sf2823" type="text" id="fm1_relationship" name ="fm1_relationship" style="background-color:#dddddd" value="" readonly="readonly"/>
</td>
<td><input class = "sf2823" type="text" id="fm1_percentage" name ="beneficiary_share" style="background-color:#dddddd" value="" readonly="readonly" onChange="percentSum()"/>
</td>
</tr>
請撥打Plunker/jsfiddle。 –
onchange不是由代碼修改的值觸發的,你必須自己觸發 –