简体   繁体   中英

loading external text from .txt to a html file

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

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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