附加锚标记

Erm*_*bel 4 html jquery

在我的应用程序中,我想让图像成为另一个页面的链接。图像放置在 html 中,

<div class="rightbuttoncontainers_footer">
  <div class="forfooterimg" id="twitterlink_indv">
    <img src="Images/tweatus.png" width="30" height="30" alt="tweat">
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我想通过脚本将这些图像作为链接,我尝试了以下操作

var twit_lk='https://twitter.com/';
$('#twitterlink_indv').append('<a href="'+twit_lk+'"/>');
Run Code Online (Sandbox Code Playgroud)

但是上面代码的输出是这样的,

<div class="rightbuttoncontainers_footer">
  <div class="forfooterimg" id="twitterlink_indv">
    <img src="Images/tweatus.png" width="30" height="30" alt="tweat">
    <a href="https://twitter.com/"></a>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

但是,我想要如下输出,

<div class="rightbuttoncontainers_footer">
  <div class="forfooterimg" id="twitterlink_indv">
    <a href="https://twitter.com/">
      <img src="Images/tweatus.png" width="30" height="30" alt="tweat">
    </a>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我怎样才能让它工作?

请帮忙,

谢谢

Mic*_*uda 5

看看这里.wrap()记录的方法。

$('#twitterlink_indv img').wrap('<a href="' + twit_lk + '" />');  
Run Code Online (Sandbox Code Playgroud)