我的 Jquery datepicker 日期更改功能代码
$(function() {
$("#datepickernew").datepicker({
minDate: '-0',
maxDate: "+3M",
onSelect: function(dateText, inst) {
var dataString = 'changedate=' + dateText;
alert(dataString);
$.ajax({
type: "POST",
url: "http://localhost/abc/abc.php",
data: dataString,
cache: false,
success: function(result) {
$('#showavialabletime').html(result);
}
});
}
});
});
这个ajax根据所选日期返回一些单选按钮
喜欢
<input id="foo2015-09-28-10-00-am" name="datetime" class="myradio" value="2015-09-28 10:00 am" type="radio">
<label for="foo2015-09-28-10-00-am" id="foo12015-09-28-10-00-am">10:00 am</label>
<input id="foo2015-09-28-10-15-am" name="datetime" class="myradio" value="2015-09-28 10:15 am" type="radio">
<label for="foo2015-09-28-10-15-am" id="foo12015-09-28-10-15-am">10:15 am</label>
并选择一个单选选项我的 jquery 警报消息
$(document).ready(function() {
$('input[name=datetime]').on('change', function() {
var date = $('input[name=datetime]:checked').val();
alert(date);
});
});
上面没有 ajax 响应,会对所选选项发出警报,但在 ajax 调用后,它不会发出警报消息。
最佳答案
由于是动态添加的,所以需要使用event delegation
$(document).ready(function () {
$('#showavialabletime').on('change','input[name=datetime]', function() {
var date=$('input[name=datetime]:checked').val();
alert(date);
});
});
关于javascript - 在更改 jquery 日期选择器的日期时调用单选按钮(单击事件)不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32816635/