将图标附加到按钮

时间:2019-05-12 09:21:13

标签: javascript html html5

我有一个要在其中使用JavaScript插入图标的按钮:

<button id="chat5" onclick="actualizarIdChat('{{ elemento.pk }}')" class="btn btn-secondary" style="background-color: maroon; border-color: transparent;border-radius: 15px;height: 60px;margin: 10px 0px 10px 0px;width: 90%;" type="button">
    <img class="border rounded-circle" style="width: 50px;height: 50px;border-color: transparent;" src="{{ elemento.producto.info_producto.contenido_multimedia.0.contenido_url }}">
    &nbsp; &nbsp; &nbsp;{{ elemento.producto.info_producto.nombre }}
</button>

这是我为使其工作而定义的代码,但是它什么也没做。

var idChat = 'chat5';
var icon = document.createElement("div");
icon.innerHTML = '<i class="fa fa-envelope"></i>';
document.getElementById(idChat).appendChild(icon);

我该怎么办?

1 个答案:

答案 0 :(得分:1)

更新javascript部分,它看起来像:

var buttonElement = document.getElementById("chat5");
buttonElement.innerHTML = buttonElement.innerHTML + '<i class="fa fa-envelope"></i>';

它将起作用

相关问题