UPDATE:jQuery:如何将值从一个函数传递给另一个?
这里是什么,我想弄清楚(见注释的问题)的简化版本:
$("document").ready(function() {
$("#startDate").datepicker({
onSelect: function(dateText, inst) {
var dateAsObject = $(this).datepicker('getDate');
var timestamp = dateAsObject.getTime(); // the timestamp of the date picked by user
}
});
// how do I get the value of timestamp to show up here?
// It also needs to update every time onSelect changes the value.
alert(timestamp);
});
你不需要有两个'$(document).ready(function(){})'fucntions。把你想要的所有功能放在一个里面。 – VTodorov
jquery中的函数只是javascript函数。 Jquery只是一堆语法糖,可以让你的事情变得简单一些。你准备好的事件处理程序就是这样。它们在页面加载时处理,并被称为先来先服务。在你的第一个准备好的处理程序中,你正在设置一个日期选择器,第二个你正在设置一个时钟。你究竟想要做什么? – scrappedcola
是的,我知道我不需要2 document.ready,但如果我把它们放入一个它不起作用。 – WebDevBooster