<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0, minimum-scale=1, maximum-scale=1">
<title>JS触发时间控件</title>
</head>
<body>
<input type="date" id="inputDate"/>
<button id="button1">使用jQuert方式</button>
<hr >
<button id="button2">使用H5+方式</button>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script type="text/javascript">
$(function(){
$('#button1').click(function(){
$("#inputDate").click();
});
$('#button2').click(function(){
try {
if (/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
//打开日期
open_date();
} else {
alert("请使用手机操作");
}
} catch (e) {}
});
function open_date(){
var styles = {};
styles.date = new Date(), styles.date.setFullYear(2019,07,22);// 默认显示的日期
styles.minDate = new Date(), styles.minDate.setFullYear(2019,07,20);// 设置最小可选日期为“2019-07-20”
styles.maxDate = new Date(), styles.maxDate.setFullYear(2019,07,29);// 设置最大可选日期为“2019-07-29”
plus.nativeUI.pickDate(function(e){
var nowDate = e.date;
var year = nowDate.getFullYear();
var month = nowDate.getMonth() + 1 < 10 ? "0" + (nowDate.getMonth() + 1) : nowDate.getMonth() + 1;
var day = nowDate.getDate() < 10 ? "0" + nowDate.getDate() : nowDate.getDate();
alert("选择的日期:" + year + "-" + month + "-" + day);
}, function(e){
console.log( "未选择日期:"+e.message );
}, styles);
}
});
</script>
</body>
</html>
js触发 html5 input type="date" 限制选择天数
最新推荐文章于 2024-04-17 11:17:07 发布