使用Javascript获取本地HTML文件的HTML代码 [英] Get HTML code of a local HTML file in Javascript

查看:307
本文介绍了使用Javascript获取本地HTML文件的HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个带有HTML,CSS,Javascript,JQuery和JQTouch的小应用程序。

这是一个LOCAL应用程序。我有一个div的index.html。当我点击此文件中的链接时,我想加载page1.html(同一文件夹)的HTML代码,并将index.html的div插入到我想要page1.html的标签中。



示例:将(page1.html)的内容注入(index.html)。



我尝试: http://api.jquery.com/load/

  $('#loadContent')。load('page1.html #test'); 

并且loadContent的内容不会改变。我将JQuery脚本包含到index.html中...



我尝试 http://api.jquery.com/html/ ,但我认为它连接到服务器。



任何想法?谢谢!

解决方案

确保在loadContent创建后调用它。

  $(function(){
$('#loadContent')。load('page1.html #test');
});


I'm developing a small application with HTML, CSS, Javascript, JQuery and JQTouch.

This is a LOCAL application. I've an index.html with some div's. When I click on a link in this file, I want to load HTML code of page1.html (same folder) and insert into a div of index.html the tag that I want of page1.html.

Example: Inject the content of (page1.html) into (index.html).

I try: http://api.jquery.com/load/

$('#loadContent').load('page1.html #test');

And the content of loadContent doesn't change. I include JQuery script into index.html...

I try http://api.jquery.com/html/ too, but I think it connect to the server.

Any idea? Thanks!

解决方案

Make sure you're calling it after loadContent has been created. The following will run your load code when the document is ready to be written to.

$(function() {
$('#loadContent').load('page1.html #test');
});

这篇关于使用Javascript获取本地HTML文件的HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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