我编写了以下代码,但今天不想重复两次(今天),所以我尝试在afterAdd之后的回调函数中编写它,但是它不起作用。为什么回调函数无法检测到它?
<script type="text/javascript">
var today = $(document).ready( function() {
var todayDate = new Date();
todayDate.setMinutes(todayDate.getMinutes() - todayDate.getTimezoneOffset());
$('input[name="purchase_date"]').val(todayDate.toISOString().slice(0,10));
});
$(".addform .repeatable").repeatable({
addTrigger: ".add",
deleteTrigger: ".del",
template: "#form_item",
afterAdd: today
});
</script>
最佳答案
首先创建today
作为函数。然后调用$(document).ready(today)
,并按照常规在代码中使用today
:
var today = function() {
var todayDate = new Date();
todayDate.setMinutes(todayDate.getMinutes() - todayDate.getTimezoneOffset());
$('input[name="purchase_date"]').val(todayDate.toISOString().slice(0, 10));
};
$(document).ready(today);
$(".addform .repeatable").repeatable({
addTrigger: ".add",
deleteTrigger: ".del",
template: "#form_item",
afterAdd: today
});