界面原型
点击新增接收人按钮,可增加一行,根据接收人双击域的框中选中的值,判断当resinType为1时,经纪人的checkbox,勾选。
//根据接收人双击域框,动态给经济人框赋值
function updateReinsType(field){
//该处的forms[0]为该界面只有一个form表单
var fieldIndex = getElementIndexInForm(document.forms[0], field);
alert("fieldIndex"+fieldIndex);
if(null!=field.value&&field.value!=''){
var url = "/policy/queryReinsCodeByType.do?ReinsCode="+field.value;
$.ajax({
url:contextRootPath + url,
type:'post',
async:false,
dataType:'json',
success:function (data) {
if(data.data[0].errorCode == '1'){
//选中经纪人选框
//该处的4,即为接收人的文本框和经纪人多选框相差几个,隐藏框也算
document.forms[0].elements[fieldIndex+4].checked = true;
document.forms[0].elements[fieldIndex+5].value='1';
}else{
document.forms[0].elements[fieldIndex+4].checked = false;
document.forms[0].elements[fieldIndex+5].value='0';
}
},
error:function () {
errorMessage("查询接收人类型错误");
}
});
}
}
获取当前文本框的位置
//form 即传个form表单,field传this即可,就是当前文本框
function getElementIndexInForm(form, field) {
var intElementIndex = -1;
var elementsCount = form.elements.length;
for (var i = elementsCount-1; i >=0; i--) {
if (form.elements[i] == field) {
intElementIndex = i;
break;
}
}
return intElementIndex;
}
部分jsp界面
<form action="/reins/interf/enquiryIntentionEdit.do" method="post" name="fm">
<table class="common" cellspacing="0" cellpadding="1">
<tr>
<td colspan="4">
<table id="ReinsReceive_Data" style="display:none">
<tbody>
<tr class="common">
<td align="left" class="right3 queryresult">
<input name="feoEnquiry.feoReinsReceives_[0].reinsCode" ondblclick="code_CodeSelect(this,'ReinsCode','0,1','Y');updateReinsType(this)" type="text" class="codestyle" style="width: 30% ;BACKGROUND-COLOR:#f8f8f8" description="接受人代码" />
<input name="feoEnquiry.feoReinsReceives_[0].reinsName" type="text" readonly class="namestyle" style="width: 65%;BACKGROUND-COLOR:#f8f8f8" />
<input name="feoEnquiry.feoReinsReceives_[0].payCode" type="hidden" />
<input name="feoEnquiry.feoReinsReceives_[0].payName" type="hidden" />
</td>
<td>
//界面上经济人的多选框
<input name="reinsTypeCheckbox" disabled="true" type="checkbox" />
<input name="feoEnquiry.feoReinsReceives_[0].reinsType" type="hidden" />
</td>
动态获取每行的,经纪人的chekbox 花了好长时间,故做记录,保存