简体   繁体   English

如何在动态创建的按钮中添加字体真棒图标

[英]How to add a font awesome icon in dynamically created button

In my HTML page I have a button in each row in a particular column.在我的 HTML 页面中,我在特定列的每一行中都有一个按钮。 User may add new rows at runtime and these buttons are also inserted alongwith rest of the fields in each row.用户可以在运行时添加新行,这些按钮也与每行中的其余字段一起插入。

The buttons are being appended using the following:正在使用以下附加按钮:

function funcAddBtnOpenPad() {   // This funct being called at page onload
// VARS FOR ADDING BUTTON IN CELL "5"
// STORING BUTTON ATTRIBUTES
var btnOpenPad = $('<input/>').attr({ type: 'button', id:'idBtnOpenPad', class:'clsBtnOpenPad', name:'btnOpenPad', value:'OpenPad' });

$('#childTable tr').each(function(tempRowIdx) {
    
// CONSTRUCT TAG FOR BUTTON "OpenPad" IN CELL "5"
    tempButtonCellTag = 'id_tIndx'+tempRowIdx+5;

// HERE WE ARE INSERTING THE BUTTON "OpenPad" <<<<
        $('#'+ tempButtonCellTag).append(btnOpenPad);
});
}

Now to insert an icon in the button I added the ref to the fa icon in the button class like the following:现在要在按钮中插入一个图标,我将 ref 添加到按钮类中的fa 图标,如下所示:

var btnOpenPad = $('<input/>').attr({ type: 'button', id:'idBtnOpenPad', class:'clsBtnOpenPad fa fa-pencil', name:'btnOpenPad', value:'OpenPad' });

However, the icon is completely missing from the button, the only change being that the size of the button and the font of the text has changed .但是,按钮中完全没有图标,唯一的变化是按钮的大小和文本的字体发生了变化

My question is: Is there a way I may insert a font awesome icon in the button so appended?我的问题是:有没有办法可以在如此附加的按钮中插入一个字体真棒图标?

Image of the html table with buttons is reproduced here.带有按钮的 html 表的图像在此处复制。

在此处输入图片说明

try adding via html () instead of appand()尝试通过 html () 而不是 appand() 添加

let ButtonCellTag = $('#'+ tempButtonCellTag);
ButtonCellTag.html(ButtonCellTag.html() + btnOpenPad)

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

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