背景:
report studio中值提示的默認(rèn)值沒辦法提供動(dòng)態(tài)設(shè)置默認(rèn)選項(xiàng),但是在實(shí)際中有時(shí)候要能動(dòng)態(tài)設(shè)置默認(rèn)選項(xiàng)。所以只能借助于html來實(shí)現(xiàn)。
實(shí)現(xiàn)功能說明: 1)登陸后設(shè)置提示第一個(gè)有效值為默認(rèn)值;2)實(shí)現(xiàn)自動(dòng)提交 (模擬自動(dòng)提交);3)僅能選擇一個(gè)有效提示值,即選擇數(shù)據(jù)項(xiàng)名稱和‘-------’無效。 實(shí)現(xiàn)方法: 1)在下值提示前后各加一個(gè)html項(xiàng)目, 內(nèi)容分別為:<span id="spanidName"> 與 </span> 注意:span id內(nèi)容根據(jù)實(shí)際設(shè)置。如附件圖片“值提示”。 此例中,我共有3個(gè)值提示,其中電壓等級(jí)與站是級(jí)聯(lián)關(guān)系,電壓等級(jí)層級(jí)高于站: <span id='spanidYear'>年份提示</span> <span id='spanidStation'>站提示</span> <span id='spanidVoltage'>電壓等級(jí)提示</span> 2) 添加一個(gè)完成按鈕。(此按鈕最終會(huì)被隱藏,代碼控制其提交) 3) 將所有提示的自動(dòng)提交取消! 4) 在頁面加一個(gè)html項(xiàng)目,內(nèi)容如下: <script. language="javascript"> //全局變量 var spanYear; var selectYear; var selectIndexYear; var spanStation; var selectStation var selectIndexStation; var spanVoltage; var selectVoltage; var selectIndexVoltage; //獲取頁面值提示對(duì)象 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); //延遲一定時(shí)間很重要,否則會(huì)報(bào)錯(cuò) }else setTimeout('oCV_NS_.promptAction(\'finish\')',100); } }
//年提示值變化(onchange事件)調(diào)用 function validateSelectYear() { getSpanInfo(); if (selectIndexYear==0 || selectIndexYear==1){ //no response } else { promptButtonFinish(); // Currently equivalent to oCV<namespace>.promptAction('finish') } }
//站提示值變化(onchange事件)調(diào)用 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') } }
//電壓等級(jí)提示值變化(onchange事件)調(diào)用 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"; } } }
//設(shè)置onchange事件 getSpanInfo() selectYear[0].onchange=validateSelectYear; selectStation[0].onchange=validateSelectStation; selectVoltage[0].onchange=validateSelectVoltage; |
|