Jquery加载外部HTML的一部分 [英] Jquery Load Part of External HTML

查看:489
本文介绍了Jquery加载外部HTML的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有一个index.html如下所示..

Basicily i have a index.html shown below..

<html>

<head>

<title>UI Test: Main Menu</title>

<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="general.js"></script>

</head>

<body>  

<input type="button" value="Details" onclick="javascript:$('#mainContainer').load('loadpage.html #name1div *');"/><br>
<div id="mainContainer">        

</div>

loadpage.html cotaints

The loadpage.html cotaints

<div id="nav1div><h3>1 DIV </h3> </div>
<div id="nav2div><h3>2 DIV </h3> </div>
<div id="nav3div><h3>3 DIV </h3> </div>
<div id="nav4div><h3>4 DIV </h3> </div>

我的目标是基本上将一个div一次加载到主容器中,i知道加载函数可以立即加载整页但这不是我需要做的。

And my objective is to basicly load 1 of the divs at a time in to the main container, i know the load function can load the full page at once but this is NOT what i need to do.

有几个看类似的问题,但似乎无法解决这个问题。 。

Had a few look at similar questions but cant seem to resolve this..

感谢所有人的帮助!

推荐答案

jQuery .load()函数允许您指定要加载的页面的一部分,而不仅仅是整个文档。

The jQuery .load() function allows you to specify a portion of a page to load, rather than just the whole document.

例如

$('#mainContainer').load('loadpage.html #nav1div');

查看 jQuery load()文档特别是它关注的地方正在加载页面碎片

这篇关于Jquery加载外部HTML的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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