背景:
report studio中值提示的默认值没办法提供动态设置默认选项,但是在实际中有时候要能动态设置默认选项。所以只能借助于html来实现。
实现功能说明: 1)登陆后设置提示第一个有效值为默认值;2)实现自动提交 (模拟自动提交);3)仅能选择一个有效提示值,即选择数据项名称和‘-------’无效。 实现方法: 1)在下值提示前后各加一个html项目, 内容分别为:<span id="spanidName"> 与 </span> 注意:span id内容根据实际设置。如附件图片“值提示”。 此例中,我共有3个值提示,其中电压等级与站是级联关系,电压等级层级高于站: <span id='spanidYear'>年份提示</span> <span id='spanidStation'>站提示</span> <span id='spanidVoltage'>电压等级提示</span> 2) 添加一个完成按钮。(此按钮最终会被隐藏,代码控制其提交) 3) 将所有提示的自动提交取消! 4) 在页面加一个html项目,内容如下: <script. language="javascript"> //全局变量 var spanYear; var selectYear; var selectIndexYear; var spanStation; var selectStation var selectIndexStation; var spanVoltage; var selectVoltage; var selectIndexVoltage; //获取页面值提示对象 function getSpanInfo(){ spanYear = document.getElementById("spanidYear");//The same name as the span id.set for year prompt selectYear = spanYear.getElementsByTagName("select"); selectIndexYear=selectYear[0].selectedIndex; spanStation = document.getElementById("spanidStation");//The same name as the span id.set for station prompt selectStation = spanStation.getElementsByTagName("select"); selectIndexStation=selectStation[0].selectedIndex; spanVoltage = document.getElementById("spanidVoltage");//The same name as the span id.set for voltage prompt selectVoltage = spanVoltage.getElementsByTagName("select"); selectIndexVoltage=selectVoltage[0].selectedIndex; }
//初始化页面 function initOnLoad() { getSpanInfo(); if(selectIndexYear==0||selectIndexYear==1) { selectVoltage[0].selectedIndex=2; selectYear[0].selectedIndex=2; //selectStation[0].selectedIndex=2; if(getFormWarpRequest().elements["cv.id"].value=="RS") { setTimeout('oCVRS.promptAction(\'finish\')',100); //延迟一定时间很重要,否则会报错 }else setTimeout('oCV_NS_.promptAction(\'finish\')',100); } }
//年提示值变化(onchange事件)调用 function validateSelectYear() { getSpanInfo(); if (selectIndexYear==0 || selectIndexYear==1){ //no response } else { promptButtonFinish(); // Currently equivalent to oCV<namespace>.promptAction('finish') } }
//站提示值变化(onchange事件)调用 function validateSelectStation() { getSpanInfo(); if (selectIndexStation==0 || selectIndexStation==1){ //no response } else { if(selectIndexYear ==0 || selectIndexYear ==1){ selectYear[0].selectedIndex=2; } promptButtonFinish(); // Currently equivalent to oCV<namespace>.promptAction('finish') } }
//电压等级提示值变化(onchange事件)调用 function validateSelectVoltage() { getSpanInfo(); if (selectIndexVoltage==0 || selectIndexVoltage==1){ //no response } else { if(selectIndexYear ==0 || selectIndexYear ==1){ selectYear[0].selectedIndex=2; } if(selectIndexStation!=0 && selectIndexStation!=1){ selectStation[0].selectedIndex=0; } promptButtonFinish(); // Currently equivalent to oCV<namespace>.promptAction('finish') } }
//页面初始加载 document.forms[0].onload=initOnLoad(); var fW = (typeof getFormWarpRequest == "function" ?getFormWarpRequest() : document.forms["formWarpRequest"]); if ( !fW || fW == undefined) { fW = ( formWarpRequest_THIS_ ?formWarpRequest_THIS_ : formWarpRequest_NS_ ); }
var buttons = fW.getElementsByTagName("BUTTON"); for (var i=0; i<buttons.length; i++) {
if (buttons[i].id.indexOf('finish') == 0) // The finish button ID starts with finish. ie: id="finishN0D5D2148x0C6BEFD0_NS_" { if (buttons[i].onclick.toString().indexOf('finish') > 0) //oCV_NS_.promptAction('finish') { //buttons[i].onclick = ValidatePage; buttons[i].style.display="none"; } } }
//设置onchange事件 getSpanInfo() selectYear[0].onchange=validateSelectYear; selectStation[0].onchange=validateSelectStation; selectVoltage[0].onchange=validateSelectVoltage; |
|