2017-04-04 7 views
1

Gibt es eine Möglichkeit, dojo/dom-construct zu verwenden, um ein Bildelement mit einem Link zu erstellen? Ich bin auf der Suche nach Entsprechung des folgenden HTML-Codes:Dojo create image with link

<a href="test.html" target="_blank"> 
    <img src="/pix/byron_bay_225x169.jpg" > 
</a> 

Antwort

3

Ja, es ist möglich!

Just do it wie folgt aus:

var anchor= domConstruct.create('a', { 
    'href': 'test.html', 
    'target': '_blank' 
}); 
var image= domConstruct.create('img', { 
    'src': '/pix/byron_bay_225x169.jpg' 
}); 
domConstruct.place(image, anchor); 
1

HTML:

<div data-dojo-attach-point="container"></div> 

JS:

var img = domConstruct.create("img", { 
       src: "/path/image.png", 
       style: "height:16px;width:16px;", 
       title: "Image", 
       onclick: function(){ 
        // onclick event 
       }, 
       onmouseenter: function(){ 
        // on mouse over event 
       }, 
       onmouseout: function(){ 
        // on mouse out event 
       } 
); 
domConstruct.place(img, this.container);