尝试用插件的形式编写

源码

 <!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><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title></title><script src="../scripts/jquery-1.3.1.js" type="text/javascript"></script><script language="javascript">(function($) {$.fn.select_interval=function(setting){var default1={//默认设置
                     select_start_id:'',select_end_id:'',data_sourse:''};var set = $.extend({},default1,setting);//将字符串转化为jquery对象
                 set.select_start_id = (typeof set.select_start_id == 'string' ? $('#'+set.select_start_id) : set.select_start_id);set.select_end_id = (typeof set.select_end_id == 'string' ? $('#'+set.select_end_id) : set.select_end_id);var select_start = {init:function(){set.select_start_id.empty();set.select_start_id.append($('<option value="" selected>请选择</option>'));for(var i = 0; i <set.data_sourse.start.length;i++){$('<option></option>').text(set.data_sourse.start[i].text).val(set.data_sourse.start[i].value).appendTo(set.select_start_id);}},change:function(){var temp_select_start_value = set.select_start_id.val();var temp_select_end_value = set.select_end_id.val();select_end.init();if (''!= temp_select_start_value){var that = this;set.select_end_id.children().each(function(){if(that.judge(temp_select_start_value,this)) $(this).remove();});}set.select_end_id.val(temp_select_end_value);},judge:function(judge_value,opt){return (parseInt(judge_value)>=parseInt($(opt).val()))? true :false;}};var select_end = {init:function(){set.select_end_id.empty();set.select_end_id.append($('<option value="" selected>请选择</option>'));for(var i = 0; i <set.data_sourse.end.length;i++){$('<option></option>').text(set.data_sourse.end[i].text).val(set.data_sourse.end[i].value).appendTo(set.select_end_id);}},change:function(){var temp_select_start_value = set.select_start_id.val();var temp_select_end_value = set.select_end_id.val();select_start.init();if (''!= temp_select_end_value){var that = this;set.select_start_id.children().each(function(){if(that.judge(temp_select_end_value,this)) $(this).remove();});}set.select_start_id.val(temp_select_start_value);},judge:function(judge_value,opt){return (parseInt(judge_value) <= parseInt($(opt).val()))? true :false;}    };var statistics = function(){if(''==set.select_start_id.val()){alert('请选择开始的时间!!');set.select_start_id.focus();    return;}if(''==this.jq_hour_end_select.val()){alert('请选择结束的时间!!');this.jq_hour_end_select.focus();return;    }confirm(this.jq_hour_start_select.val()+'---'+this.jq_hour_end_select.val());    }//初始化设置
                 select_start.init();select_end.init();set.select_start_id.bind('change',function(){ select_start.change();});set.select_end_id.bind('change',function(){ select_end.change(); });};    })(jQuery);$(function(){var josn1 = {'start':[{'text':'星期一','value':1},{'text':'星期二','value':2},{'text':'星期三','value':3},{'text':'星期四','value':4},{'text':'星期五','value':5},{'text':'星期六','value':6},{'text':'星期日','value':7}],'end':[      {'text':'星期一','value':1},{'text':'星期二','value':2},{'text':'星期三','value':3},{'text':'星期四','value':4},{'text':'星期五','value':5},{'text':'星期六','value':6},{'text':'星期日','value':7}]};$.fn.select_interval({select_start_id:'hour_start_select',select_end_id:'hour_end_select',data_sourse:josn1    });    $('#statistics_btn').bind('click', function(){if(''==$('#hour_start_select').val()){alert('请选择开始的时间!!');$('#hour_start_select').focus();    return;}if(''==$('#hour_end_select').val()){alert('请选择结束的时间!!');$('#hour_end_select').focus();return;    }confirm($('#hour_start_select').val()+'---'+$('#hour_end_select').val());    });});</script>
</head>
<body><div id="mode_div">按天统计:<select id='hour_start_select'></select>至<select id="hour_end_select"></select>&nbsp;&nbsp;<button id="statistics_btn">统计</button></div>
</body>
</html>

演示
按天统计: 至   统计

转载于:https://www.cnblogs.com/shuaisam/archive/2012/05/21/2511387.html

jquery 选择时间(小时)区间(四)相关推荐

  1. jquery 选择时间(小时)区间(二)

    select hours interval 选择时间区间 完成jquery 选择时间(小时)区间(一)中同样的功能 源码 View Code <!DOCTYPE html PUBLIC &quo ...

  2. jQuery框架学习第四天:使用jQuery操作元素的属性与样式

    jQuery框架学习第一天:开始认识jQuery jQuery框架学习第二天:jQuery中万能的选择器 jQuery框架学习第三天:如何管理jQuery包装集 jQuery框架学习第四天:使用jQu ...

  3. python根据excel时间表统计24小时各小时区间点的个数

    1.首先使用excel中的HOUR()函数,将日期数据(年/月/日 时:分:秒)转换为小时,表格命名为hour.xlsx: 2.使用python读取excel数据hour.xlsx,将小时列转换为列表 ...

  4. jQuery杂项进阶(四)

    文章目录 一.$ 的替换 二.使用JSONP实现跨域 三.jQuery 杂项方法.实用工具.回调对象.延迟对象参考 ☆ 四.jQuery 自身属性参考 ☆ 五.jQuery 插件介绍和参考 ☆ jQu ...

  5. jQuery 基础教程 (四)之jQuery中的DOM操作

    一.jQuery 中的 DOM 操作 (1)DOM(Document Object Model-文档对象模型):一 种与浏览器, 平台, 语言无关的接口, 使用该接口可以 轻松地访问页面中所有的标准组 ...

  6. [转帖]jQuery框架学习第四天:使用jQuery操作元素的属性与样式

    一.摘要 本篇文章讲解如何使用jQuery获取和操作元素的属性和CSS样式. 其中DOM属性和元素属性的区分值得大家学习. 二.前言 通过前面几章我们已经能够完全控制jQuery包装集了,  无论是通 ...

  7. jquery源码分析(四)——回调对象 Callbacks

    借用百度百科来说明下回调函数: 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用来调用其所指向的函数时,我们就说这是回调函数.回调函数不是由该 ...

  8. jquery 向上滚动【四】个人认为好一些,哈

    <!--示例html--> <html> <head> <title>滚动</title> <script type="te ...

  9. Jquery调用webService的四种方法 【转载】

    本文转载自:http://space.itpub.net/221062/viewspace-580298 我总结几个关键点 1. 服务必须声明为ScriptService(否则会出现下面的问题) 2. ...

最新文章

  1. Groovy学习摘要
  2. 320. Generalized Abbreviation-- back tracking and bit manipulation(待续)
  3. VMM2012应用指南之2- 准备VMM2012虚拟机
  4. html如何超链接到servlet
  5. 那些关于区块链革命的事情
  6. php pclzip.lib.php,php使用pclzip类实现文件压缩的方法(附pclzip类下载地址)
  7. SAS数据挖掘方法论 ─ SEMMA
  8. 7-2 最长公共子序列 (10 分)(思路加详解)
  9. 前端学习(2248)git是怎么运作的
  10. python变量以及类型(含笔记)
  11. 世界上十大数据中心,全球数字经济顶梁柱
  12. Became Jane(成为简.奥斯丁)
  13. (3)FPGA面试技能提升篇(TCL脚本)
  14. if语句中的赋值与判断
  15. 2.LVS的三种工作模式_NAT模式
  16. 新来的妹子把几百万数据放入了内存,系统立马爆了,我不得已做到了妹子傍边,手把手教妹子...
  17. html 怎么调用js中函数返回值,JavaScript 函数
  18. android自动点击相应位置脚本,轻易连使用说明-自动连点器-安卓自动点击脚本 | MOS86...
  19. 深度学习入门(二)训练并使用Keras模型
  20. Excel图表制作(二):滚动条实现动态图表

热门文章

  1. 智能机器人与系统高精尖创新中心2018年度开放基金项目申报通知
  2. 清华发布《中国AI发展报告2018》:中科院系统AI论文产出全球第一
  3. 深度学习将眼睛变成健康“指示器”
  4. 看完50多家阵亡的初创企业,我们发现了AI创业的5个行业潜规则
  5. 测试 C、Python、Java 等 16 种编程语言的 Hello World:7 种存在 Bug?
  6. 太难了!开源项目如何商业化?
  7. Ubuntu左边启动器移到底部及自动隐藏
  8. 【Maven学习】Nexus私服代理其他第三方的Maven仓库
  9. 背水一战 Windows 10 (40) - 控件(导航类): AppBar, CommandBar
  10. JavaScript新知:sessionStorage and localStorage