簡體   English   中英

在JavaScript中添加帶有圖片的錨標簽

[英]adding an anchor tag with image in javascript

我在JQuery中創建了一個圖像標簽。 現在,我需要再添加一個錨標簽。 如何使用JavaScript實施?

我嘗試了這個:

var imgg = document.createElement("img");
imgg.className='myclass';
$( ".myclass" ).add( "<a href="#">Test</a>" );   

但它不起作用。 它應顯示為:

  <img src=""><a href="#"></a>

我應該使用哪個函數在img標簽中添加一個錨標簽?

做就是了:

$("<img>").addClass("myclass").after("<a href='#'></a>").appendTo("body");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM