如何使用jQuery显示DIV所在的页面 [英] How to show a page where a DIV is with jQuery
问题描述
您好,我在index.html页面中有一个DIV:
Hello I have a DIV in the page index.html:
<div id="form"></div>
现在,我需要一种使用jQuery的方法来显示该DIV中的另一页. 我需要调用并加载的页面是contact.php 这是一个简单的HTML + PHP联系表格. 有没有一种方法可以用jQuery在DIV所在的index.html页面中加载contact.php的内容? 感谢您的帮助!
Now I need a way with jQuery to show another page inside that DIV. The page I need to call and load there is contact.php It is a simple HTML + PHP contact form. Is there a way to load with jQuery the contents of contact.php inside index.html page where the DIV is? Thanks for your help!
推荐答案
$("#form").load("contact.php");
jQuery load
函数从服务器获取数据(在本例中为contact.php
),并用该数据替换所选元素的内容(在本例中为#form
).
The jQuery load
function fetches data from the server (in this case from contact.php
) and replaces the contents of the selected element (in this case #form
) with that data.
如有必要,您还可以将数据传递到正在加载的页面中,并提供一个回调函数,该函数将在完成时执行.
If necessary, you can also pass data into the page being loaded, and also supply a callback function that will be executed upon completion.
有关更多信息,请参见 jQuery API .
For more information, see the jQuery API.
这篇关于如何使用jQuery显示DIV所在的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!