Javascript 如何将一个函数的值传递给另一个函数

Javascript 如何将一个函数的值传递给另一个函数,javascript,jquery,Javascript,Jquery,我有一个函数,可以得到一个值。我想在.ready()函数中获取该值 我将在其中推动该功能: <a onclick="selectMonth(<%=month%>)" href="dayOffInsertDeleteByDate.do?barberId=<%=barberId %>&startTime=<%=timeInterval.get(0) %>&date=<%=j+1 %>&insertDeleteWay=bul

我有一个函数,可以得到一个值。我想在
.ready()
函数中获取该值

我将在其中推动该功能:

<a onclick="selectMonth(<%=month%>)" href="dayOffInsertDeleteByDate.do?barberId=<%=barberId %>&startTime=<%=timeInterval.get(0) %>&date=<%=j+1 %>&insertDeleteWay=bulkDate&closeTime=<%=timeInterval.get(timeInterval.size()-1) %>&year=<%=year%>&month=<%=month%>&barberName=<%=barberName%>">
var selectMonthh=null;
function selectMonth(val){
  selectMonthh=val;
  $( "body" ).data( "foo", selectMonthh );
  alert(val+" .."+$( "body" ).data( "foo"));
}
我想在这里得到值:

jQuery(document).ready(function(){
   alert(selectMonthh);
}

这将在您的警报框中输入“月”值,但我不确定您想要实现什么,因此可能有更好的方法

jQuery(document).ready(function(){
   alert(<%=month=>);
}
jQuery(文档).ready(函数(){
警惕();
}

我不确定我是否理解您的问题。您是否知道文档就绪函数将在链接的onclick事件之前执行?这意味着,无论您打算如何在这些函数之间移动该值,当您尝试读取该值时,该值都将被取消设置。对此我不是很确定。我可以在任何va中以某种方式设置该值吗ready函数中的变量和访问?您可以创建一个全局变量并将信息存储在那里。但正如我所说,它在document ready上始终是未定义的。如果您能够在document ready上设置值,您可能从服务器获得了值。为什么不使用该值在dom ready.jQuery(document).ready(function()上调用函数呢{selectMonth();}。这将把值设置为selectMonthh。