为什么我看到MS jQuery示例使用`$(domReady); `? [英] Why do I see MS jQuery samples use `$(domReady); `?

查看:98
本文介绍了为什么我看到MS jQuery示例使用`$(domReady); `?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有人注意到这一点,但我注意到 jQuery示例我在MS上看到倾向于使用不同的格式:

I don't know if anyone ELSE has noticed this, but I noticed the jQuery samples I see on MS tend to use a different format:

<script type="text/javascript">  

  $( domReady );  

  function domReady() {  
     $('#btn').click( showMessage );  
  }  

  function showMessage() {  
     $('#message').fadeIn('slow');  
  }  
</script> 

这与以下内容不同:

$(document).ready( function() {

  $('#btn').click( showMessage );  

  function showMessage() {  
     $('#message').fadeIn('slow');  
  }  

});

使用一种语法比另一种语法有什么优势吗?

Is there any advantage of using one syntax over the other?

我承认,MS方式确实看起来更干净。

I will admit, the MS way does look cleaner.

推荐答案

唯一真正的区别在于可读性和组织性。

The only real difference is readability and organization.

技术上与

$( function() {

  $('#btn').click( showMessage );  

  function showMessage() {  
     $('#message').fadeIn('slow');  
  }  

});

这是 $(文件).ready(...)的简写

这篇关于为什么我看到MS jQuery示例使用`$(domReady); `?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆