简体   繁体   English

如何使用php或javascript将包含html的.txt文件中的内容加载到div中?

[英]How to load content from a .txt file with html in it … into a div using php or javascript

I have an index page with 5 divs. 我有5个div的索引页。 1 div is the header menu div where i put the buttons to link to the other pages in the website, but i do not want to make like 10 other htmls. 1 div是标题菜单div,在其中我放置了一些按钮以链接到网站上的其他页面,但我不想像其他10个html一样。 In the middle area i have 3 divs ... on the left a vertical space where i would like to load a submenu with other buttons than the ones in the header menu ... but this is something else, also in the middle there is a right vertical div similar to this one but will be with text only. 在中间区域,我有3个div ...在左侧有一个垂直空间,我想在该子菜单中加载带有除标题菜单中的按钮之外的其他按钮的子菜单...但这是其他内容,也在中间区域与此类似的右垂直div,但仅包含文本。 and in the center of middle is the main content div. 在中间的中心是主要内容div。 and here is where i want to load html form an external .txt file ... and all this just by clicking the links in the menu. 这是我要在其中加载HTML格式的外部.txt文件的地方...而所有这些,只需单击菜单中的链接即可。 so if i click on the home button i get a specified text (index.txt) in the main content div, and if i click on contact i get in the main content the contact.txt content. 因此,如果我单击“主页”按钮,则会在主要内容div中获得指定的文本(index.txt),如果我单击“联系人”,则会获得主要内容中的contact.txt内容。 and this way i only have the index file as html and the other as text only. 这样,我只有索引文件为html,而其他文件仅为文本。

You could issue an AJAX request to download the content of the txt filed, when user clicks the button or anchor. 当用户单击按钮或锚点时,您可以发出AJAX请求以下载txt字段的内容。

Are you familiar with any js libraries like jQuery? 您是否熟悉jQuery之类的js库? Simple example utilizing jQuery: 使用jQuery的简单示例:

<input type="button" id="show_content">Show content</input>
<div id="content_div"></div>
<script type="text/javascript">
  $("#show_content").click(function(){
    $("#content_div").load("/my_text_content.txt");
  });
</script>

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

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