1

大家好,我在这里有一个 Javascript 代码,它创建 HTML 按钮 onload,按钮属性通过 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);  

}
4

2 回答 2

2

改为.. this.class_this.className

于 2013-02-07T13:06:10.753 回答
0

当你到达 alert 参数时,传入这个:

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

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

于 2013-02-07T13:06:51.190 回答