$(function() {,function

來源:互聯網
上載者:User

$(function() {,function

項目中出現”$(function() { “類似這樣的代碼。

$(document).ready(function(){              // 程式段           })等價於$(function(){              // 程式段           })


$(function() {}

這是JQuery的文法,$表示JQuery對象,可以有好幾種用法。比如傳遞選取器字串、頁面對象等,如果直接傳函數體進去,表示當頁面載入完畢時執行這個函數,就是你所問的用法。
 
function()函數的具體用法

函數實際上是一個統一的代碼塊,你可以隨時調用它。

Creating PHP functions:
建立PHP函數的方法:

All functions start with the word "function()"
所有函數的開頭必須加上“function()”
Name the function - It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number)
給函數命名:最好的命名方法是,函數擁有的名稱和它所表現的功能相一致。名字可以包含字母或底線(不可以包含數字)。
Add a "{" - The function code starts after the opening curly brace
加上一個“{”:函數的代碼必須寫在“{”符號之後。
Insert the function code
插入一段函數代碼
Add a "}" - The function is finished by a closing curly brace
加上一個“}”:函數書寫完畢後,必須加上“}”符號。
Example
案例
A simple function that writes my name when it is called:
下面是一個簡單的PHP函數案例,當我們調用它時,它可以輸出我們的名字:

<html><body>
<?phpfunction writeMyName() { echo "Kai Jim Refsnes"; }
writeMyName();?>
</body></html>
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.