Javascript 如何将图片附加到函数中,并将参数作为src附加到函数中

Javascript 如何将图片附加到函数中,并将参数作为src附加到函数中,javascript,jquery,Javascript,Jquery,我有一个函数,我调用了3次,但我想知道是否可以使用图像作为参数 如果答案是肯定的,那么我的下一个问题是:如何将参数附加到我的 守则: function getAnchorTags(link, image) { let anchors = ($('<a/>', { 'href': link })).html('this is where the img etc. should come'); return anchors; } $(functi

我有一个函数,我调用了3次,但我想知道是否可以使用图像作为参数

如果答案是肯定的,那么我的下一个问题是:如何将参数附加到我的

守则:

function getAnchorTags(link, image) {
    let anchors = ($('<a/>', {
        'href': link
    })).html('this is where the img etc. should come');
    return anchors;
}

$(function () {
    $(rowEblock().append(getEblock()).appendTo('.panel-footer'));
    $('#anchorAppender').append(getAnchorTags('#'), getAnchorTags('#'), getAnchorTags('#'));
});
函数getAnchorTags(链接、图像){
设锚点=($('
上面的代码,但在javascript中(带有函数)并使用参数

调用
getAnchorTags()
的代码:


$(“#anchorAppender”).append(getAnchorTags(“#”)、getAnchorTags(“#”)、getAnchorTags(“#”);
您可以传递
src
并在
html()中使用它,如:

function getAnchorTags(link, image) {
    let anchors = ($('<a/>', {
        'href': link
    })).html('<img src="'+image+'">');

    return anchors;
}

$(function () {
    $(rowEblock().append(getEblock()).appendTo('.panel-footer'));
    $('#anchorAppender').append(getAnchorTags('#','image_src_path'), getAnchorTags('#','image_src_path'), getAnchorTags('#','image_src_path'));
});
函数getAnchorTags(链接、图像){
设锚点=($(''){
“href”:链接
})).html(“”);
返回锚;
}
$(函数(){
$(rowEblock().append(getEblock()).appendTo(“.panel footer”);
$(“#anchorAppender”).append(getAnchorTags(“#”、“image#src_path”)、getAnchorTags(“#”、“image#”、“image#src_path”)、getAnchorTags(“#”、“image#src_path”);
});
function getAnchorTags(link, image) {
    let anchors = ($('<a/>', {
        'href': link
    })).html('<img src="'+image+'">');

    return anchors;
}

$(function () {
    $(rowEblock().append(getEblock()).appendTo('.panel-footer'));
    $('#anchorAppender').append(getAnchorTags('#','image_src_path'), getAnchorTags('#','image_src_path'), getAnchorTags('#','image_src_path'));
});