jQuery $(function(){})和$(document).ready一样吗? [英] jQuery $( function() {} ) and $(document).ready the same?
本文介绍了jQuery $(function(){})和$(document).ready一样吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要在字段上设置工作日期选择器,我必须将此脚本放在我的元素中
To have a working datepicker on a field, I have to put this script inside my element
$( function() {
$( "#date_datepicker" ).datepicker( { dateFormat: "yy-mm-dd" } );
});
删除 $(function(){
使得日期选择器不起作用。
Removing the $( function() {
makes the datepicker not work.
这是否意味着 $(function(){
与 $(document).ready
?
我正在尝试优化我的javascript代码,所以知道这可能有所帮助。
I'm trying to optimize my javascript codes so knowing this might help.
推荐答案
请参阅以下摘录 http://api.jquery.com/ready/
以下所有三种语法都是等效的:
All three of the following syntaxes are equivalent:
-
$(document).ready(handler)
-
$()。ready(处理程序)
(不建议这样做) -
$(处理程序)
$(document).ready(handler)
$().ready(handler)
(this is not recommended)$(handler)
这篇关于jQuery $(function(){})和$(document).ready一样吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文