简体   繁体   English

将图标标签添加到按钮中的innerHTML

[英]add the icon tag to the innerHTML in a button

I'm trying to create a function in JavaScript, which on the button click changes class and adds a green checkmark, which is the icon tag in html.我正在尝试在 JavaScript 中创建一个函数,该函数在按钮上单击更改类并添加一个绿色复选标记,即 html 中的图标标记。

I tried this:我试过这个:

function markerValg(btnID) {
    knap = document.getElementById(btnID);
    knap.classList.remove("unselected");
    knap.classList.add("selected");
    document.getElementById(btnID).innerHTML = += <i class="fa fa-check ikon"></i>

将最后一行代码更改为

document.getElementById('test').innerHTML = '<i class="fa fa-check ikon"></i>';
<button id='test'>Check</button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM