血泪奋斗
作者血泪奋斗·2017-09-07 11:13
商业智能工程师·地球村

cognos默认选取当前年月

字数 1180阅读 1778评论 1赞 2

注意:这个需要在提示页面中加载,从而传到页面;

<span id ="y" >
。。。。
这儿是你的年和月的值提示
。。。。
</span>

<script>
function init(){
var theA = document.getElementById ("y");
var theB = theA.getElementsByTagName("select");
theB[0].remove(0);
theB[0].remove(0);
theB[1].remove(0);
theB[1].remove(0);
var cur_date = new Date();
var cur_year = cur_date.getFullYear();
var cur_month = cur_date.getMonth()+1;
for (var i = 0; i <theB[0].length; i++) { //循环搜索下拉列表中和当前年份caption相等的值

        var temp = theB[0].options[i].text;
        //alert(temp);
                       if (temp == cur_year) {
            //alert('Find!!! ' + temp + ' ' + i);
                               theB[0].options[i].selected = true;
            break;
                       }
              }

for (var i = 0; i <theB[1].length; i++) { //循环搜索下拉列表中和当前年份caption相等的值

        var temp = theB[1].options[i].text;
        //alert(temp);
                       if (temp == cur_month) {
            //alert('Find!!! ' + temp + ' ' + i);
                               theB[1].options[i].selected = true;
            break;
                       }
              }

promptButtonFinish();

}

</script>

<body onload=init()>

这样就自动提交了,参数从提示页面传到页面。

如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!

2

添加新评论1 条评论

血泪奋斗血泪奋斗商业智能工程师地球村
2017-09-07 11:28
还有另外一种比较传统的办法,就是用cognos的方法: &amp;lt;script language=&amp;quot;javascript&amp;quot;&amp;gt; var f = getFormWarpRequest(); var list = f._oLstChoicesPromptYear;//PromptYear是组件的自定义名称 var list1 = f._oLstChoicesPromptMonth;//PromptMonth是组件的自定义名称 var cur_date = new Date(); var cur_year = cur_date.getFullYear(); var cur_month = cur_date.getMonth()+1; list.remove(1); list.remove(0); list.removeAttribute(&amp;quot;hasLabel&amp;quot;); list1.remove(1); list1.remove(0); list1.removeAttribute(&amp;quot;hasLabel&amp;quot;); for (var i = 0; i &amp;lt;list.length; i++) { //循环搜索下拉列表中和当前年份caption相等的值 var temp = list.options[i].text; //alert(temp); if (temp == cur_year) { //alert(&amp;#039;Find!!! &amp;#039; + temp + &amp;#039; &amp;#039; + i); list.options[i].selected = true; break; } } for (var i = 0; i &amp;lt;list1.length; i++) { //循环搜索下拉列表中和当前年份caption相等的值 var temp = list1.options[i].text; //alert(temp); if (temp == cur_month) { //alert(&amp;#039;Find!!! &amp;#039; + temp + &amp;#039; &amp;#039; + i); list1.options[i].selected = true; break; } } &amp;lt;/script&amp;gt;
Ctrl+Enter 发表

作者其他文章

相关问题

X社区推广