从.txt加载外部文本到一个html文件 [英] loading external text from .txt to a html file

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

问题描述

我知道如何使用

 < div id =text>来加载.txt文件中的外部文本。 < DIV> 

和javascript

  $(#text)。load(pathtofile / content.txt); //元素的ID应该是字符串形式

但是这可以在两个< p>标记而不是插入到div中?如果是这样怎么样?

谢谢 解决方案

完成。

这就是:

HTML:

 < p id =text>< / p> 

JQuery:

  $('#text')。load(pathtofile / content.txt); 



更新:

要从文件的某个段落中获取文本,请尝试以下操作:

HTML:

 < div id =tempDIvstyle =display:none ;>< / DIV> 
< p id =text>< / p>

JQuery:

  $('#tempDiv')。load(pathtofile / content.txt); $($#$ b $('#text')。html($('#tempDiv')。find('#theParagraphId')。html()); 


I know how to load external text from a .txt file using

<div id="text"> <div> 

and javascript

 $("#text").load("pathtofile/content.txt"); // element's id should be in string form

but can this be done between two < p > tags instead of inserting into a div? if so how?

Thanks

解决方案

Yes it can absolutely be done.
This is how:
HTML:

<p id="text"></p>

JQuery:

 $('#text').load("pathtofile/content.txt");

.

UPDATE:
To get the text from only a paragraph from the file, try this:
HTML:

<div id="tempDIv" style="display:none;"></div>
<p id="text"></p>

JQuery:

 $('#tempDiv').load("pathtofile/content.txt");
 $('#text').html($('#tempDiv').find('#theParagraphId').html());

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

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