问题描述
我是jquery的新手.我刚刚读到这两个是等效的:
I'm new to jquery. I've just read that these 2 are equivalent:
$(document).ready(function() {});
$(function() {});
哪个是更好的做法,还是被更多接受?第一个让我更加清晰,因为它声明了"document.ready"部分-但是,我还是jquery的新手.可能对任何有jquery经验的人来说,第二种选择同样清楚地意味着"document.ready".我应该选择以下哪个选项?
Which one is better practice, or more accepted? The first one strikes me as clearer in that it states the "document.ready" part - but then again, I'm new to jquery. It could be that to anyone with any experience in jquery, the second option just as clearly implies "document.ready". Which of these options should I choose?
推荐答案
随意使用其中之一.就像您认为的那样,后一个版本是$(document).ready()
的简写.
Feel free to use either one of them. Just as you think, the latter version is a shorthand for $(document).ready()
.
自从jQuery发行以来,第一个选项就与第二个选项相反.
The first option was available since the beginning of jQuery releases as oppose to the second option.
我个人更喜欢第二个版本,因为它比较短.
Personally I prefer the second version for it is shorter.
这篇关于jQuery:选择document.ready方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!