年,月 ,季节 下拉框

css:
   <style>
    .combo-title { padding-right: 5px }

      .combo-data > div { display: inline-block }

</style>

html:

 <div class="row">
                <div class="col-xs-2 topic" style="padding-left: 0">指标公共维度:</div>
                <div class="col-xs-7 combo-data">
                    <span class="combo-title">频率:</span>
                    <div id="rotate"></div>
                    <div class="data-combo-year"></div>//开始年
                    <div>
                        <div class="data-combo"></div>//开始月或季节
                    </div>
                    <span style="color:darkgreen">———</span>
                    <div class="data-combo-year"></div>//结束年
                    <div>
                        <div class="data-combo"></div>//结束月和季节
                    </div>
                </div>
            </div>

  js 代码:

var $dataCombo = $(".data-combo"),
       $yearCombo = $(".data-combo-year");

 var year_f, year_last, year_s;
    var yearArr = [];
    var month = [
        {id: ‘1‘, text: ‘1月‘},
        {id: ‘2‘, text: ‘2月‘},
        {id: ‘3‘, text: ‘3月‘},
        {id: ‘4‘, text: ‘4月‘},
        {id: ‘5‘, text: ‘5月‘},
        {id: ‘6‘, text: ‘6月‘},
        {id: ‘7‘, text: ‘7月‘},
        {id: ‘8‘, text: ‘8月‘},
        {id: ‘9‘, text: ‘9月‘},
        {id: ‘10‘, text: ‘10月‘},
        {id: ‘11‘, text: ‘11月‘},
        {id: ‘12‘, text: ‘12月‘}
    ];
    var roteArr = [{"id": 1, "text": "年份", "value": "1"},
    {"id": 2, "text": "季度", "value": "2"},
    {"id": 3, "text": "月份", "value": "3"}];/*频率选择数组*/
    var season = [
        {id: ‘1‘, text: ‘1季度‘},
        {id: ‘2‘, text: ‘2季度‘},
        {id: ‘3‘, text: ‘3季度‘},
        {id: ‘4‘, text: ‘4季度‘}
    ];/*季度*/
    getYears();/*获得近4年*/
    function getYears() {
        var nowDate = new Date();
        year_f = nowDate.getFullYear();
        year_last = year_f - 1;
        year_s = year_f - 3;
        var id, text;
        for (var y = year_f; y >= year_s; y--) {
            id = y.toString();
            text = id + "年";
            yearArr.push({id: id, text: text});
        }
    }
 /*结束-月框加载*/
    $dataCombo.last().combobox({
        valueField: "id",
        textField: "text",
        data: month,
        value: "1月",
        editable: true,
        width: 80,
        height: 30,
        panelWidth: 80,
        panelHeight: ‘auto‘,
        formatter: function (row) {
            return "<span class=‘glyphicon glyphicon-check‘> " + row.text + "</span>"
        },
        onSelect:function () {
           alert("结束月");
        }
    });
    /*开始-月框加载*/
    $dataCombo.first().combobox({
        valueField: "id",
        textField: "text",
        data: month,
        value: "1月",
        editable: true,
        width: 80,
        height: 30,
        panelWidth: 80,
        panelHeight: ‘auto‘,
        formatter: function (row) {
            return "<span class=‘glyphicon glyphicon-check‘> " + row.text + "</span>"
        },
        onSelect: function (node) {
            alert("开始月");
            yearChange(null, node);
        }

    });
    /*结束年份*/
    $yearCombo.last().combobox({
        valueField: "id",
        textField: "text",
        data: secondYear,
        value: year_f + "年",
        editable: true,
        width: 80,
        height: 30,
        panelWidth: 80,
        panelHeight: ‘auto‘,
        formatter: function (row) {
            return "<span class=‘glyphicon glyphicon-check‘> " + row.text + "</span>"
        },
        onSelect: function (node) {
            alert("结束年");
            yearChange2(node, null);
        }
    });
 /*结束年份*/
    $yearCombo.last().combobox({
        valueField: "id",
        textField: "text",
        data: secondYear,
        value: year_f + "年",
        editable: true,
        width: 80,
        height: 30,
        panelWidth: 80,
        panelHeight: ‘auto‘,
        formatter: function (row) {
            return "<span class=‘glyphicon glyphicon-check‘> " + row.text + "</span>"
        },
        onSelect: function (node) {
            alert("结束年");
            yearChange2(node, null);
        }
    });
    /*开始年份*/
    $yearCombo.first().combobox({
        valueField: "id",
        textField: "text",
        data: yearArr,
        value: year_last + "年",
        editable: true,
        width: 80,
        height: 30,
        panelWidth: 80,
        panelHeight: ‘auto‘,
        formatter: function (row) {
            return "<span class=‘glyphicon glyphicon-check‘> " + row.text + "</span>"
        },
        onSelect: function (node) {
            alert("开始年");
            yearChange(node, null);
        }
    });
 /*第一个年框改变
    * @params yearNode:在年框里调用这个方法的时候,把选择的年份节点传过来,月份节点参数为null,
    * */
    function yearChange(yearNode, monNode) {
        var rotate = $("#rotate").combobox("getText");/*获取频率*/
        console.log($("#rotate").combobox("getText"),"rotate");
        var flagArr = [], second = [];/*设置中转数组*/
        if (rotate == "月份") {
            flagArr = month.slice();
        } else if (rotate == "季度") {
            flagArr = season.slice();
        }
        var startYear = yearNode ? yearNode.id : ( $yearCombo.first().combobox("getText"));
        startYear = parseInt(startYear);
        var endYear = parseInt($yearCombo.last().combobox("getText"));
        var start = monNode ? monNode.id : ($dataCombo.first().combobox("getText"));/*第一个月或季度*/
        start = parseInt(start);
        var end = parseInt($dataCombo.last().combobox("getText"));
        console.log($dataCombo.last().combobox("getText"));
        /*第二个月或季度*/
        console.log(startYear, start, endYear, end, "1");
        secondYear = yearArr.slice(0, (year_f - startYear + 1));
        if (yearNode) {/*如果是月框改变,就不必要重新加载年框的数据*/
            $yearCombo.last().combobox("loadData", secondYear);
        }
        if (startYear >= endYear) {
            $yearCombo.last().combobox("setValue", startYear);
            second = flagArr.slice(start - 1);/*第二个月或季度显示的数组*/
            $dataCombo.last().combobox("loadData", second);
            if (start >= end) {
                $dataCombo.last().combobox("setValue", start);
            }else{
                $dataCombo.last().combobox("setValue", end);
            }
        } else {
            second = flagArr.slice();
            $dataCombo.last().combobox("loadData", second);
            $dataCombo.last().combobox("setValue", end);
        }
    }
    /*第二个年框改变*/
    function yearChange2(yearNode, monNode) {
        var rotate = $("#rotate").combobox("getText");
        var flagArr = [], second = [];
        if (rotate == "月份") {
            flagArr = month.slice();
        } else if (rotate == "季度") {
            flagArr = season.slice();
        }
        var endYear = yearNode ? yearNode.id : ( $yearCombo.last().combobox("getText"));
        endYear = parseInt(endYear);
        var startYear = parseInt($yearCombo.first().combobox("getText"));
        var start = monNode ? monNode.id : ($dataCombo.first().combobox("getText"));
        start = parseInt(start);
        var end = parseInt($dataCombo.last().combobox("getText"));
        console.log(startYear, start, endYear, end, "2");
        if (startYear == endYear) {
            second = flagArr.slice(start - 1);
            $dataCombo.last().combobox("loadData", second);
            if (start > end) {
                $dataCombo.last().combobox("setValue", start);
            }else{
                $dataCombo.last().combobox("setValue", end);
            }
        } else {
            second = flagArr.slice();
            $dataCombo.last().combobox("loadData", second);
            $dataCombo.last().combobox("setValue", end);
        }
    }
  /*频率框加载*/
    $("#rotate").combobox({
        valueField: "id",
        textField: "text",
        data: roteArr,
        editable: true,
        width: 70,
        height: 30,
        panelWidth: 70,
        panelHeight: ‘auto‘,
        value: ‘月份‘,
        formatter: function (row) {
            return "<span class=‘glyphicon glyphicon-check‘> " + row.text + "</span>"
        },
        onSelect: function (recoder) {
            if (recoder.id == 1) {/*1:频率为年;2:季节;3:月份*/
                $dataCombo.parent().hide();
            } else {
                var firstArr,defaultVal;
                firstArr=recoder.id==2?season:month;
                defaultVal=recoder.id==2?"1季度":"1月";
                $dataCombo.combobox("clear");
                $dataCombo.parent().show();
                $dataCombo.combobox("loadData", firstArr);
                $dataCombo.combobox("setText", defaultVal);
//                $dataCombo.combobox("setValue", "1");  #这里有一个bug,要是用setValue,设置dataCombo下拉框的值,会在它重新加载“loadData”时,
把自己的选中事件onSelect,执行一遍,这个问题很奇怪。用setText,就不发生。但是我上面在改变年的时候用setText,还是会重新加载的时候执行onSelecte事件。
            }
        }
    });

  

时间: 2024-10-25 08:16:00

年,月 ,季节 下拉框的相关文章

java 下拉框级联及相关(转)

ActionLintsner是所有监听器的父类,其它监听器可以监听的事件都可以被它捕获ItemListener用于捕获带有item的组件产生的事件,如ComboBox,CheckBox,RadioButton,ToggleButton,接口中定义的itemStateChanged(ItemEvent e)将执行需要在已选定(或已取消选定)项时发生的操作 import java.awt.Dimension; import java.awt.Font; import java.awt.Rectang

C#学习笔记(20140911)-下拉框、日历、pannel控件的使用

晚上学习了下拉框.日历.pannel控件的使用,这几个控件看上去好像没有之前的一些控件那么简单,但是使用起来还是很方便.使用完了后,才发现真的和之前的几种控件差不多. 最了一个小小的模块:每日签到填写心情模块. 主要功能有: 1. 点击日历可以填写签到日期,并在签到内容中自动添加: 2. 可以选择心情,已经写好三种心情供选择.只需要选择一下就可以自动把心情填写到今日心情展示模块中,使用起来很方便. 3. 手动填写心情.手懂填写的时候可以和日期.选择的心情一起自动填写到心情展示区. 4. 历史心情

HTTP 错误 403.14 - Forbidden0--Asp.net实现下拉框和列表框的连动

走过了牛腩老师的新闻发布系统,漫游过了孙鑫老师的Html,在427沐浴第一缕冬日阳光的美丽月底,小编迎来了北大青鸟的Asp.net,北大青鸟,高大上的赶脚有么有,哈哈哈,开始了小编的.net之旅. 首先,小编来简单介绍一下Asp.net,她是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们. 指 Active Server Pages(动态服务器页面) ,运行于

JS年月日三级联动下拉框日期选择代码

原博客网址: http://www.cnblogs.com/gdcgy/p/5467742.html 由于工作中涉及到生日编辑资料编辑,年月日用上面网址案例:bug提示: 编辑生日栏的[年]或者[月],之前保存的具体的[日]就不显示啦,产品说不管编辑哪个数据,其他数据不变: 然后自己改了一下代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xh

html年月日下拉联动菜单 年月日三下拉框联动

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head><title>年月日三下拉框联动</title>

.net简单页面后台绑定下拉框,按钮,分页 后台cs文件

二.cs文件 using System;using System.Collections.Generic;using System.Web.UI;using System.Web.UI.WebControls;using BS.EAP.DBAccess;using System.Data;using BS.EAP.Authentication;using BS.EAP.BizMgt.DataQuery;using System.Web.Security;using System.Collecti

Web 1三级联动 下拉框 2添加修改删除 弹框

Web  三级联动 下拉框 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { private MyDBDataContext _Context = new MyDBD

自定义SWT控件一之自定义单选下拉框

一.自定义下拉控件 自定义的下拉框,是自定义样式的,其中的下拉框使用的是独立的window,非复选框的下拉框双击单机其它区域或选择完之后,独立window构成的下拉框会自动消失. package com.view.control.select; import java.util.ArrayList; import java.util.List; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite;

Flex下拉框

<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:s="library://ns.adobe.com/flex/spark" xmlns:mx="library://ns.adobe.com/flex/mx" creationComplet