看看 ajax : "target 0": "render": "anchor tag"
我最初使用的是“glyphicon glyphicon-chevron-right”。
我想在点击时将其更改为“glyphicon glyphicon-chevron-down”。
$(document).ready(function () {
$("#PageNo").text(currentPage);
tblErrorLog = $('#tblErrorLog').DataTable(
{
serverSide: true,
ajax: {
url: '@Url.Content("~/ErrorLogs/ErrorLogDataSaurce")',
data: ErrorLogParameter,
dataSrc: ErrorLogGridDataBound,
type: "POST"
},
select: true,
paging: false,
searching: false,
info: false,
columnDefs: [
{
targets: 0,
render: function (data, type, full, meta) {
return '<a id=' + full.ID + ' onclick="return ViewErrorDetails(' + full.ID + ')"><i class="glyphicon glyphicon-chevron-right"></i></a>'
}
},
{
targets: 1,
data: "Message",
orderable: true
},
{
targets: 2,
data: "Source",
orderable: true
},
],
});
});
最佳答案
你的 anchor 应该是这样的。
<a class="glyphicon glyphicon-chevron-right" id=' + full.ID + ' onclick="return ViewErrorDetails(' + full.ID + ', this)"></a>
并在函数 ViewErrorDetails() 中添加此类代码。
function ViewErrorDetails(id, itm)
{
$(itm).removeClass('glyphicon-chevron-right');
$(itm).addClass('glyphicon-chevron-left');
}
关于javascript - 如何更改我的 ajax 渲染属性的 anchor 标记中的 glyphicon?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41074414/