JS为表格每行添加点击事件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shujuelin/article/details/86290208
<table>
<tr>
<td onclick=clickaction(this)>td1</td>
<td onclick=clickaction(this)>td2</td>
</tr>
</table>
 
js部分:
function clickaction(td){
alert(td.innerText);
}

=================================================

//==========  渠道控制 ============================/
function initChannelTable(){
    loading();
    $.ajax({
        url : chanActionPath + "queryDataList&",
        type : 'post',
        data : tableData,
        success : function(response) {
            $(".loading").remove();
            var resp = eval('(' + response + ')');
            $("#channelTable").html("");// 清空内容
            $.each(resp.root, function(i, item) {

                $("#channelTable").append(
                    '<tr onclick= "clickaction(\''+item.channelId+'\')">'
                    +'<td><a style="float: left">'+item.channelName+'</a></td>'
                    +'<td  style="background-color: #FFFFFF;color: #1fa075;" >'
                    +'<button style="background-color: #FFFFFF;" onclick="showChannelOut(\''+item.channelName+'\',\''+item.channelId+ '\')">修改</button></td>'
                    +'<td><a style="text-align: right">>></a></td> '
                    +'</tr>'
                );

             });
            initStarTable();
        },
        failure : function(response) {
            error();
        }
    });
}

function clickaction(id) {

    channelId = id;
    start = 1;

    if(evaluateType == '0'){
        evaluateType="";
    }
    tableData = {
        start : start,
        limit : pageSize,
        channelId : channelId,
        evaluateType :evaluateType
    };
    initStarTable()
}

猜你喜欢

转载自blog.csdn.net/shujuelin/article/details/86290208