Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

javascript - bootstrap datepicker今天默认为(bootstrap datepicker today as default)

I am using this bootstrap-datepicker for my datepicker.(我正在使用这个bootstrap-datepicker作为我的datepicker。)

I'd like the datepicker to choose "today" for start day or default day.(我希望datepicker为开始日或默认日选择“今天”。) I cannot figure out how to set "today" automatically, so I did an inefficient way(我无法弄清楚如何自动设置“今天”,所以我做了一个低效的方式) HTML:(HTML:) <input type="text" value ="today();" id="datepicker"/> JS:(JS:) $('#datepicker').datepicker(); function today(){ var d = new Date(); var curr_date = d.getDate(); var curr_month = d.getMonth() + 1; var curr_year = d.getFullYear(); document.write(curr_date + "-" + curr_month + "-" + curr_year); } Online Sample: http://jsfiddle.net/BXZk2/(在线样本: http//jsfiddle.net/BXZk2/) Just looking for an easy solution to make the default day as "TODAY".(只是寻找一个简单的解决方案,使默认日为“今天”。) Thanks(谢谢)   ask by olo translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This should work:(这应该工作:)

$("#datepicker").datepicker("setDate", new Date()); And for autoclose ( fiddle ):(而对于autoclose( 小提琴 ):) $('#datepicker').datepicker({ "setDate": new Date(), "autoclose": true }); jQuery > datepicker API(jQuery> datepicker API)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...