简体   繁体   English

"Jquery 加载外部 HTML 的一部分"

[英]Jquery Load Part of External HTML

Basicily i have a index.html shown below..基本上我有一个 index.html 如下所示..

<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>

The loadpage.html cotaints loadpage.html 内容

<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>

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.我的目标是基本上一次将 1 个 div 加载到主容器中,我知道加载函数可以一次加载整个页面,但这不是我需要做的。

Had a few look at similar questions but cant seem to resolve this..看过一些类似的问题,但似乎无法解决这个问题..

All help is appreciated thanks guys!感谢大家的帮助!

The jQuery .load()<\/code> function allows you to specify a portion of a page to load, rather than just the whole document. jQuery .load()<\/code>函数允许您指定要加载的页面的一部分,而不仅仅是整个文档。

eg例如

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

To load DIVs one after another, define a counter要一个接一个地加载 DIV,定义一个计数器

var curDiv = 1; // current Div

jQuery load<\/code>可以很方便的加载页面片段,像这样

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM