简体   繁体   English

如何将一个类从一个文件嵌入到另一个文件?

[英]How to embed a class from one file to another?

Is there a way to embed a class from another page in my site? 有没有办法在我网站的另一个页面中嵌入课程? Lets say I have this code in the page "index.html" 可以说我在“ index.html”页面中有此代码

<div class="cls1">
  content of div...
</div>

and I want to embed it to another page "anotherpage.html" in my site. 我想将其嵌入到我网站的另一个页面“ anotherpage.html”中。 So I do: 所以我做:

<iframe src"?"></iframe>

What should i put instead the ? 我应该放什么呢?

note I want to take from the first file only a divs with the same class 注意,我只想从第一个文件中提取具有相同类的div

You can separate your html to two files, and then add iframe to another file. 您可以将html分为两个文件,然后将iframe添加到另一个文件。

First file: 第一个文件:

<div class="something">
Tralala
</div>

Second File: 第二档:

<iframe src="/path/to/your/first/file.html">
</iframe>

iframe requires src (source) parameter, which should be a valid URL where html file lays. iframe需要src(源)参数,该参数应该是放置html文件的有效网址。 However you can use javascript to assume this type of behaviour. 但是,您可以使用javascript来假定这种行为。

Using jquery for example: 以jquery为例:

$('.div2').html($('.div1').html());

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

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