Input 点击出日期时间组件
<input type="text" class="form-control" id="datetime" placeholder="Time" >
点第一次没反应,点一下别的地方再点就好使了为什么呢
$('#datetime').click(function(){
$(this).datepicker({
autoclose: true,
});
});
Input 点击出日期时间组件
<input type="text" class="form-control" id="datetime" placeholder="Time" >
点第一次没反应,点一下别的地方再点就好使了为什么呢
$('#datetime').click(function(){
$(this).datepicker({
autoclose: true,
});
});
$( "#datepicker_date" ).datepicker({
dateFormat: "yymmdd"
});
<input id="datepicker_date" type="text" name="date"></input>
这样就够了, 为什么要给input设置click.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker();
} );
</script>
</head>
<body>
<p>Date: <input type="text" id="datepicker"></p>
</body>
</html>
因为我是全局的,不想用到的页面就在底部初始化一下 所以我写到了全局js文件里 最后是这样的
/**
* 日期插件实现
*/
if ( $("input").hasClass("datetime") ){
$( '.datetime' ).datepicker({
autoclose: true,
});
}
1 回答858 阅读✓ 已解决
1 回答1.1k 阅读
2 回答774 阅读
2 回答622 阅读
2 回答607 阅读
1 回答682 阅读
2 回答529 阅读
第一次点击是实例化日期组件,第二次开始才是操作日期组件,所以应该直接调用组件