---
title: "$(document).ready()使用讨论"
author: "bd2007"
date: "2011-08-02T17:00:14Z"
tags: []
categories: ["Web前端"]
slug: "document-ready"
draft: false
lastmod: "2011-08-02T17:00:14Z"
id: 1138374
url: "https://bd2007.iteye.com/blog/1138374"
---

一、先为说说 $(document).ready() 的功能：
    1. JQuery API对 $(document).ready() 的解释是：当DOM载入就绪可以查询及操纵时绑定一个要执行的函数。
    2. 我的理解：$(document).ready() 用于当前页面加载完成后，就执行其定义的方法，用于异步加载，提交页面响影的速度，用于在一个页面中包含多个页面的情况（一个页面中使用多个iframe）。
 
二、使用方法如下：
    1. 将页面中使用iframe的地方使用div代替；并定义div的ID属性。代码示例如下：
&lt;div id="MyNoticesDiv" width="100%" height="195px"&gt;
			 		
&lt;/div&gt;
 
    2. 在js定义$(document).ready()，代码示例如下：
&lt;script language="JavaScript" type="text/javascript"&gt;

	$(document).ready(function(){ 

		$.ajax({
			url : '${base}/merchantHome/findMyNotices.action?merchantNoticeDto.limit=3',
			type : 'post',
			dataType : "text",
			success : function(text) {
				isPro = false;
				if(null != text &amp;&amp; "" != text){
					$('#MyNoticesDiv').html(text);
				}
			}
		});		

	})

&lt;/script&gt;
 
    3. 就这么简单，页面完成后，通过js再加载div中要显示的内容。