简体   繁体   English

将内容从一个元素复制到另一个

[英]Copy Content From One Element to Another

I've got a image slider I'm using, each image has a caption below it, which looks a little like this. 我有一个正在使用的图像滑块,每个图像下方都有一个标题,看起来像这样。

<ul class="image-slider">
    <li>
      <img src="img-1.jpg">
      <figcaption>Fig1. - A view of the pulpit rock in Norway.</figcaption>
    </li>
    <li>
      <img src="img-2.jpg">
      <figcaption>Fig2. - A view of lighthouse.</figcaption>
    </li>
    ...
</ul>

Using a bit of jQuery, this image slider slides along, showing one image and their caption. 使用一些jQuery,此图像滑块会滑动,显示一个图像及其标题。

I've got a description box on my website where I want my caption to actually appear. 我的网站上有一个描述框,我希望标题真正出现在这里。

<div class="description">
  <h3>Image Gallery</h3>
  <p class="caption">This is where I want my caption to appear</p>
</div>

I can't use any absolute positioning or CSS, I need the caption text to move to across to the p tag using something else, possibly Javascript. 我不能使用任何绝对定位或CSS,我需要标题文本使用其他可能的Javascript移动到p标签。

Is this possible? 这可能吗?

Any help is appreciated. 任何帮助表示赞赏。 Thanks in advance! 提前致谢!

Shouldn't this work? 这不行吗?

$(".caption").text($('li:nth-child('+i+')').text());

where i is a variable (INT) that could get i++ when moving forward in the image slider and get substracted by one ( i-- ) when one goes one step back in the image slider. 其中i是一个变量(INT),当在图像滑块中向前移动时可以获取i++当在图像滑块中向后退一步时,该变量将减一( i-- )。

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

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