我知道如何使用从.txt文件加载外部文本
<div id="text"> <div>
和javascript
$("#text").load("pathtofile/content.txt"); // element's id should be in string form
但是这可以在两个<p>标记而不是插入div?如果是,如何?
感谢
要仅从文件中的一段中获取文本,请尝试以下操作:
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);