JQUERY 无法识别 datetimepicker onSelect
JQUERY datetimepicker onSelect is not recognized
我正在尝试使用 jquery 中的日期时间选择器。每当您 select 一个新日期时,我都想清除一些输入字段,但我的 onSelect 并没有真正起作用。
首先,它只在文档加载时触发一次。之后它再也不会开火了。
其次,onSelect 不适用于匿名函数。
这个不行
$(document).ready(function() {
$(function () {
$('#dateValue').datetimepicker({
format: 'YYYY-MM-DD',
onSelect: function() {
console.log("testing");
}
});
});
});
这确实有效,但仅在文档加载时触发,然后再也不会
$(document).ready(function() {
$(function () {
$('#dateValue').datetimepicker({
format: 'YYYY-MM-DD',
onSelect: console.log("testing")
});
});
});
index.html
中我的head标签中导入的文件
<head>
<meta charset="UTF-8">
<title>....</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="myCSS.css">
</head>
编辑:我搞砸了,忘了给出错误信息
Uncaught TypeError: option onSelect is not recognized!
at Function.<anonymous> (bootstrap-datetimepicker.min.js:8)
at Function.each (jquery.min.js:2)
at Object.l.options (bootstrap-datetimepicker.min.js:8)
at c (bootstrap-datetimepicker.min.js:9)
at HTMLInputElement.<anonymous> (bootstrap-datetimepicker.min.js:9)
at Function.each (jquery.min.js:2)
at n.fn.init.each (jquery.min.js:2)
at n.fn.init.a.fn.datetimepicker (bootstrap-datetimepicker.min.js:9)
at HTMLDocument.<anonymous> (script.js:3)
at j (jquery.min.js:2)
试穿声明
$("#dateValue").on("onselect",function(){ console.log("testing"); });
您必须使用 dp.change
日期更改时触发的事件。
$('#dateValue').datetimepicker({
format: 'YYYY-MM-DD',
});
$("#dateValue").on("dp.change", function() {
console.log("testing");
});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<div class='input-group date' id='dateValue'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
您正在使用 Bootstrap datetimepicker
component.The onselect
事件不是其中的一部分。
你必须使用
$("#dateValue").on("dp.change", function (e) {
//your code
});
我正在尝试使用 jquery 中的日期时间选择器。每当您 select 一个新日期时,我都想清除一些输入字段,但我的 onSelect 并没有真正起作用。 首先,它只在文档加载时触发一次。之后它再也不会开火了。 其次,onSelect 不适用于匿名函数。
这个不行
$(document).ready(function() {
$(function () {
$('#dateValue').datetimepicker({
format: 'YYYY-MM-DD',
onSelect: function() {
console.log("testing");
}
});
});
});
这确实有效,但仅在文档加载时触发,然后再也不会
$(document).ready(function() {
$(function () {
$('#dateValue').datetimepicker({
format: 'YYYY-MM-DD',
onSelect: console.log("testing")
});
});
});
index.html
中我的head标签中导入的文件<head>
<meta charset="UTF-8">
<title>....</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="myCSS.css">
</head>
编辑:我搞砸了,忘了给出错误信息
Uncaught TypeError: option onSelect is not recognized!
at Function.<anonymous> (bootstrap-datetimepicker.min.js:8)
at Function.each (jquery.min.js:2)
at Object.l.options (bootstrap-datetimepicker.min.js:8)
at c (bootstrap-datetimepicker.min.js:9)
at HTMLInputElement.<anonymous> (bootstrap-datetimepicker.min.js:9)
at Function.each (jquery.min.js:2)
at n.fn.init.each (jquery.min.js:2)
at n.fn.init.a.fn.datetimepicker (bootstrap-datetimepicker.min.js:9)
at HTMLDocument.<anonymous> (script.js:3)
at j (jquery.min.js:2)
试穿声明
$("#dateValue").on("onselect",function(){ console.log("testing"); });
您必须使用 dp.change
日期更改时触发的事件。
$('#dateValue').datetimepicker({
format: 'YYYY-MM-DD',
});
$("#dateValue").on("dp.change", function() {
console.log("testing");
});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.js"></script>
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/js/bootstrap-datetimepicker.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.37/css/bootstrap-datetimepicker.min.css" rel="stylesheet" />
<div class='input-group date' id='dateValue'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
您正在使用 Bootstrap datetimepicker
component.The onselect
事件不是其中的一部分。
你必须使用
$("#dateValue").on("dp.change", function (e) {
//your code
});