jQuery ready () method
Examples
Use ready () function to make after the document is loaded it is available:
$ (Document) .ready (function () {
$ ( "Button"). Click (function () {
. $ ( "P") slideToggle ();
});
});
$ ( "Button"). Click (function () {
. $ ( "P") slideToggle ();
});
});
try it"
Definition and Usage
ready event occurs when the DOM (document object model Document Object Model) is loaded and the page is fully loaded (including images) when.
Since this event occurred after the document is ready, so all other jQuery events and functions into the incident is a very good practice. As shown in the above examples.
ready () method specifies the code executed when the ready event occurs.
Tip: ready () method should not be the <body onload = ""> together.
grammar
It allows the use of the following two syntaxes:
$(document).ready(function)
ready () method can only be used for the current document, so no selector:
$(function)
参数 | 描述 |
---|---|
function | 必需。规定当文档加载后要运行的函数。 |