我使用https://github.com/eternicode/bootstrap-datepicker并希望在日期发生变化时触发ajax调用。jQuery:输入值返回undefined
首先通过插入changeDate
事件来确定何时更改日期。然后警告在文本框中输入到屏幕的价值...
http://bootstrap-datepicker.readthedocs.org/en/latest/events.html#changedate
这里是我的小提琴....
http://jsfiddle.net/MangoMM/nY5C6/3/
HTML
<div class="input-group date">
<input class="form-control" placeholder="Select Date" readonly="1"
data-provide="datepicker" data-date-format="yyyy-mm-dd"
data-date-start-date="today()" data-date-autoclose="true"
data-date-days-of-week-disabled="[2,4,6,0]"
data-date-today-highlight="1" name="appointment[date]"
type="text" id="appointment[date]" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
jQuery的
$(".input-group.date").on('changeDate', function(){
alert(event.type + " is fired: " + $('#appointment[date]').val());
});
我试过各种组合,包括$(this).val()等,但没有运气...
为什么我的输入值显示为undefined?我如何获得文本框中的值?
@ T.J.Crowder - 如何是题外话的问题,它是如何没有提供足够的信息?我提供了一个精确显示我的代码的小提琴,并且提供了大量信息来回答我的问题。 – Gravy
@肉汁:“在问题本身”。现在相关的代码不依赖于非现场资源,这没关系。小提琴是一个*附件*,而不是将代码**置于**问题中的替代品。 SO应该独立存在;从现在开始,jsFiddle可能会消失一小时/一天/一月/一年。 –