简体   繁体   English

如何在图像标签周围包裹HTML标签?

[英]how to wrap html tag around image tag?

I want to convert below html image tag 我想在html图像标签下转换

<img src="img-1.jpg" width="290" height="420" class="frameImage" />

to following code using jquery. 使用jQuery以下代码。

<table class="frame" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="border-top" colspan="3"></td>
  </tr>
  <tr>
    <td class="border-left"></td>
    <td><div class="image-frame"><img src="img-1.jpg" width="290" height="420" class="frameImage" />
        <div class="top-left"></div>
        <div class="top-right"></div>
        <div class="bottom-right"></div>
        <div class="bottom-left"></div>
      </div></td>
    <td class="border-right"></td>
  </tr>
  <tr>
    <td class="border-bottom" colspan="3"></td>
  </tr>
</table>
  1. Append the whole table without the image to the document. 将没有图像的整个表格追加到文档中。
  2. Find div with class 'image-frame' and place the image inside it. 用“ image-frame”类找到div并将图像放在其中。
$('img[src=img-1.jpg]').before('<table class="frame" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td class="border-top" colspan="3"></td>
  </tr>
  <tr>
    <td class="border-left"></td>
    <td><div class="image-frame"><img src="img-1.jpg" width="290" height="420" class="frameImage" />
        <div class="top-left"></div>
        <div class="top-right"></div>
        <div class="bottom-right"></div>
        <div class="bottom-left"></div>
      </div></td>
    <td class="border-right"></td>
  </tr>
  <tr>
    <td class="border-bottom" colspan="3"></td>
  </tr>
</table>').remove();

You should be able to do something like this: 您应该能够执行以下操作:


    $('.image-frame').html('<img src="img-1.jpg" width="290" height="420" class="frameImage" /%gt;')

but it would require you to print the table first and then insert the image into the table 但这需要您先打印表格,然后将图像插入表格

这不是一个确切的答案,但是您可能对jQuery-ImageFrame感兴趣

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

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