一:jquery、bootstrap实现日期下拉选择

点击文本框弹出窗口

弹窗显示日期时间选择下拉

年份取当前年份的前后各5年

天数随年份和月份的变化而变化

点击保存,文本框中显示选中的日期

代码部分的实现

引入bootstrap文件和外部js文件

<script src="../gongju/bootstrap-3.3.7-dist/js/jquery-1.11.2.min.js" type="text/javascript"></script>

    <script src="../gongju/bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript"></script>

    <script src="riqi.js" type="text/javascript"></script>

    <link rel="stylesheet" type="text/css" href="../gongju/bootstrap-3.3.7-dist/css/bootstrap.min.css"/>

文本框、引入bootstrap弹窗代码

<body>
<input type="text" name="riqi" id="riqi" data-toggle="modal" data-target="#myModal"/> <!--给文本框定义id--> <!--弹窗部分-->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel">修改界面</h4>
</div>
<div class="modal-body">
<!--弹窗主题内容--> </div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
<button type="button" class="btn btn-primary" id="baocun">保存</button>
</div>
</div>
</div>
</div>
</body>

外部js文件代码部分

$(document).ready(function(){
var str="<select id='nian'></select><select id='yue'></select><select id='ri'></select>";
$(".modal-body").html(str);
fillnian();
fillyue();
fillri(); /*年份变化时,调用月份和日期的方法*/
$("#nian").change(function(){
fillyue();
fillri();
})
/*月份变化时,调用天数的方法*/
$("#yue").change(function(){ fillri();
}) $("#baocun").click(function(){ /*点击保存,取select的value值,并添加到文本框*/
var nn=$("#nian").val();
var mm=$("#yue").val();
var ri=$("#ri").val(); $("#riqi").val(nn+"-"+mm+"-"+ri); }) /*下面分别是填充年份/月份/日期的方法*/
function fillnian()
{
var n=new Date();
var nian=parseInt(n.getFullYear());
var str="";
for(var i=nian-5;i<nian+6;i++)
{
str+="<option value='"+i+"'>"+i+"</option>"
}
$("#nian").html(str);
}
function fillyue()
{ var str="";
for(var i=1;i<;i++)
{
str+="<option value='"+i+"'>"+i+"</option>"
}
$("#yue").html(str);
}
function fillri()
{
var nn=$("#nian").val();
var mm=$("#yue").val();
var biao=31;
if(mm==4 || mm==6 ||mm==9 ||mm==11)
{ biao=30;
}
if(mm==2)
{
if((nn%4==0 && nn%100 != 0) || nn%400==0)
{
biao=29;
}else
{
biao=28;
}
}
var str="";
for(var i=1;i<biao+1;i++)
{
str+="<option value='"+i+"'>"+i+"</option>";
}
$("#ri").html(str);
}
})

二:bootstrap jquery UI自带动画的日期选择器

引入bootstrap jquery ui文件,直接引入下面几句话,不用改


<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css">
 

代码实现部分

<body>

<p>日期:<input type="text" id="datepicker"></p>

</body>

 <script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>

最新文章

  1. heredoc技术
  2. 浅入tomcat
  3. excel 两列比较内容是否相同
  4. [转]DevExpress.XtraGrid.GridControl gridView自动列宽代码
  5. java获取本月或某月的第一天和最后一天
  6. [Javascript] bukld &#39;SQL&#39; like object tree
  7. HTML前端技术(JS的使用,包括数组和字符串)
  8. 犯罪团伙利用POS机刷信用卡积分转卖 年获利千万
  9. node文件中的package.json文件解析
  10. 百度UEditor图片上传或文件上传路径自定义
  11. A start job is running for xxx to stop
  12. 【JAVASCRIPT】json 与 string
  13. Centos7.2 启用iptables
  14. 销售行业ERP数据统计分析都有哪些维度?
  15. Jmeter(二十四)_服务器性能监控
  16. Day04.a(对象类型的转换,多态)
  17. 读书笔记--《Effective C#》总结
  18. 继承user表需要配置
  19. SQLServer调WebService &amp; 错误解决:请求格式无法识别
  20. 1.1.17 Word在表格中插入竖排文字,显示一半

热门文章

  1. NYOJ 20.吝啬的国度-DFS+STL(vector保存上一节点)
  2. Codeforces Round #451 (Div. 2) B. Proper Nutrition【枚举/扩展欧几里得/给你n问有没有两个非负整数x,y满足x&#183;a + y&#183;b = n】
  3. 【Spring源码解析】—— 简单工厂模式的BeanFactory的超简版实现
  4. 树(tree)
  5. Web模糊测试工具Powerfuzzer
  6. 搭建 Maven ---基础入门
  7. 洛谷1373小a和uim之大逃离
  8. 全面了解Nginx主要应用场景
  9. Scut游戏服务器引擎6.0.5.0发布-支持C#脚本
  10. 15.【nuxt起步】-Nuxt使用jsweixin sdk