我正在使用bootstrap datetimepicker并尝试保存日期 当弹出页面上的警报时,它显示为空白。 请帮忙,如果需要更多信息,请告诉我。 这两行代码都在同一个html.erb页面上
这是我用来设置日期的脚本
<div class='input-group date' id='datetimepicker1'>
<!--Trying to figure out how to capture the data -->
<input type='text' data-date-format="MM/DD/YYYY" class="form-control" />
<span class="input-group-addon"><span class="glyphicon glyphicon-calendar"></span>
脚本我试图用来存储数据
<script type="text/javascript">
$('#datetimepicker1').on('change', function() {
alert($('#datetimepicker1').val());
});
</script>
初始化datetimepicker
$(".datetimepicker1").datetimepicker({
endDate: new Date,
format: "yyyy-mm-dd",
autoclose: true,
minViewMode: 1,
todayBtn: "linked"
});
答案 0 :(得分:0)
无论我能理解什么,你可能都在寻找这个!
$(document).ready(function (){
$('#myDate').datepicker({ format: 'yyyy-mm-dd'
});
$('#myDate').on('change', function() {
var x = $('#myDate').val();
//alert("value of date is "+ x);
//do some ajax call and put/post the date like,
$.ajax({
type: 'post',
url: 'http://yourUrl',
data: {"date": x}, //in case String is to be sent!
success: function(x) {
//do some stuff on success, you can go with callback implementation too
console.log(x);
},
error: function(err){
console.log(err);
}
})
});
});