显示类名

Displaying a class name

本文关键字:显示      更新时间:2023-09-26
大家好,我这里有一个Javascript代码,它创建HTML按钮,按钮属性通过ASP页面从数据库中提取。现在我想显示这些属性,我可以显示id、类型和值,但类显示为未定义。我转到浏览器上的页面,检查了元素,并且显示了类,但没有显示在警告框上。请帮忙。。。
function createButtons(tbID, tbClass, tbType, tbValue, onClick) {
return ''n<input'
                + (tbID ? ' id=''' + tbID + '''' : '')
                + (tbClass ? ' class=''' + tbClass + '''' : '')
                + (tbType ? ' type=''' + tbType + '''' : '')
                + (tbValue ? ' value=''' + tbValue + '''' : '')
                            + (onClick ? ' onclick='''+ onClick + '''':'')
                            + '>';
}

function DisplayButtons(cableData) {
var newContent = '';
$.each(cableData, function (i, item) {
newContent += createButtons(
        item.CommonCable,
        "unclickedButton",
        "submit",
        item.CommonCable,
        'alert(this.id + " " + this.class + " "+"clicked")'
    );
});

$('#Categories').html(newContent);  
}

this.class更改为this.className。。

当您到达警报参数时,传入以下内容:

'alert(this.id + " " +' +  $(this).attr(class) + ' + " "+"clicked")'

您可以使用jQuery来获取类名。