你好,我想在 jquery datepicker
中动态关闭日期,但问题是我如何将变量从一个函数传递到另一个函数。这是代码。
<script>
$(function() {
$("#datepicker").datepicker({
beforeShowDay: function(date) {
var day = date.getDate();
if (day == 31) /* i want to pass dynamic value here */ {
return [false];
} else {
return [true];
};
}
});
$(".ui-state-default").on('click', function(e) {
var value = e.toElement.outerText; /* i want to pass this value to beforeShowDay*/
})
});
</script>
检查我的演示 here
最佳答案
您只需在点击方法之外声明值。并将 31 替换为值。之后,它将起作用。
$(function(){
var value;
$( "#datepicker" ).datepicker({
beforeShowDay: function(date){
var day=date.getDate();
if (day==value)/* i want to pass dynamic value here */{
return [false];
} else{
return [true];
};
}});
$( ".ui-state-default" ).on('click',function(e){
value= e.toElement.outerText; /* i want to pass this value to beforeShowDay*/
})
});
关于javascript - 如何在 jquery datepicker 中动态关闭日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32278353/