十、页面加载时对复选框、下拉列表、单选框默认进行选中及提交请求时判断单选按钮是否选中

1、功能点1:页面加载时,对复选框进行默认选中

<input type="hidden"  id="exchFeatureCodeValue" value="<c:out value='${actionDescList.exchFeatureCode}'/>">
<tr>
    <td><input type="checkbox" name="exchFeatureCode" id="STR0001" value="STR0001" onclick="esClick()">STR0001:金额较大</td>
</tr>
<tr>
    <td><input type="checkbox" name="exchFeatureCode" id="STR0002" value="STR0002" onclick="esClick()">STR0002:累计金额较大</td>
</tr>
function load() {
    exchFeatureCode=document.getElementById("exchFeatureCodeValue").value;
    testSelect(exchFeatureCode);
}
function testSelect(exchFeatureCode){
       var featureCodeChkbox = document.getElementsByName("exchFeatureCode");
    for(var j=0;j<featureCodeChkbox.length;j++){
         if(exchFeatureCode.indexOf(featureCodeChkbox[j].value)>=0){
          featureCodeChkbox[j].checked=true;
      }
    }
} 
函数说明:String.IndexOf 方法 (Char, [startIndex], [count])
报告指定字符在此实例中的第一个匹配项的索引。搜索从指定字符位置开始,并检查指定数量的字符位置
1)str1.IndexOf("人")     :查找“人”在str1中的索引值(位置),如果找到该字符,则为 value 的索引位置;如果未找到,则为 -1
备注: [startIndex] 可选项,搜索起始位置。不设置则从0开始
2)str1.IndexOf("字",start,end);//从str1第start+1个字符起,查找end个字符,查找“字”在字符串STR1中的位置[从第一个字符算起]注意:start+end不能大于str1的长度
经典示例:
test.indexof('d')      从前向后 定位 d 第一次出现的位置
test.indexof('d',1)    从前向后 定位 d 从第三个字符串第一次出现的位置
test.indexof('d',5,2)  从前向后 定位 d 从第5 位开始查,查2位,即 从第5位到第7位;
lastindexof() :             从后向前 定位 字符和字符串
View Code

2、功能点2:回写页面时,下拉列表中数据从后台获取;选中分类下拉列表中的自然人时,【导出Excle】按钮置为不可用

 1 功能2.1:后台java进行回写到前台代码(框架为spring1.2.8+ibatis1.0)
 2 map.put("selectPattern", pattern);//前台获取的pattern值
 3 map.put("code1", "个人");
 4 map.put("code2", "组织");
 5 return new ModelAndView(this.getGenQueryView(), map);
 6 
 7 功能点2.2:获取后台值进行下拉列表默认选中
 8 <td align="center">分类</td>
 9 <td>
10 <select id="pattern" name="pattern" style="width:210px;" onchange="fun(this)">
11     <option value="<c:out value='${code1}'/>"
12         <c:if test="${code1==selectPattern}">selected="selected"</c:if>>
13         <c:out value="${code1}" />
14     </option>
15     <option value="<c:out value='${code2}'/>"
16         <c:if test="${code2==selectPattern}">selected="selected"</c:if>>
17         <c:out value="${code2}" />
18     </option>
19 </select>
20 </td>
21 
22 <td style="border:0" align="center" colspan="6">
23     <input name="query" id="query" type="submit" value="查 &nbsp;询" />
24     <input id="exportButton" type="button" value="导出Excel" onclick="javaScript: exportExcl();" /> 
25 </td>
26 
27 功能点2.3:当分类选中自然人时,导出按钮置为失效状态
28 function fun(obj){
29 var patternValue=$("#pattern").find("option:selected").text();//选中的文本
30 if(patternValue=="自然人"){
31         $("#exportButton").attr("disabled", true); 
32     }else{
33         $("#exportButton").attr("disabled", false);
34     }
35 }
View Code

 3、功能点3:点击【审核通过】按钮时,判断是否选中一条待审核记录的前面的单选按钮

<input  type="button" value="审核通过" onclick="updateAudit('dataConAuditAction.do?action=updateReportAuditById','radio')">

function updateAudit(dispacher, control) {
    var currentpage = document.getElementById("currentpagevalue").value;
    var count = 0;
    var frm = document.dataAuditListFrom;
    var tmp;
    for (i = 0; i < frm.elements.length; i = i + 1) {
        var e = frm.elements[i];
        if (e.type === control && e.checked === true) {
            count = count + 1;
            tmp = e.value;
        }
    }
    if (count > 0) {
        $.ajax({
            type: "post",
            url: dispacher,     
            data: {"insurCode" : tmp,
                   "currentPage" : currentpage,
                   "pageDirection" : 'current'
                },    
            success: function(data) {
                if(data == 'OK' && dispacher=='kyDataHeadAuditAction.do?action=updateReportAuditById'){
                    alert( '审核成功!点击确定刷新列表');
                    seachHeadPage('');
                }else if (data == 'OK') {
                    alert( '审核成功!点击确定刷新列表');
                    location.reload();
                }else{
                    alert('审核失败,请稍后再试!');
                }
            },
            error: function(data) {
                alert("系统错误,请稍后再试!");
            }
       })

    } else {
        alert("请选择一条记录!");
    }
}
View Code

 

posted @ 2018-01-10 15:50  爱笑的berg  阅读(1055)  评论(0编辑  收藏  举报