我正在使用 jquery-datatables-editable ( http://code.google.com/p/jquery-datatables-editable/ ) 来使用 jQuery 管理我的表,但是我需要做的是当我编辑一个单元格时,我想要获取我刚刚编辑的单元格的 id 和类。我怎样才能做到这一点?这是我的代码的一部分:
//creating the table
var table = $('<table id="mytable" border="1" cellpadding="1" cellspacing="1"></table>');
var head = $('<thead><tr><th>Name</th><th>IP</th><th>Status</th><th>Last Seen</th><th>Pref. Smithers</th><th>Debug LvL</th></tr></thead>');
table.append(head);
var body = $('<tbody></tbody>');
for (var i = 0; i < x.length; i++) {
//using xml to fill the cells
var ip = x.item(i).getAttribute("id");
var row = $('<tr id="' + ip + '"></tr>');
var id = $('<td id="ip" class="' + ip + '"></td>');
var ls = $('<td id="lastseen" class="' + ip + '"></td>');
var nm = $('<td id="name" class="' + ip + '"></td>');
var st = $('<td id="status" class="' + ip + '"></td>');
var dblvl = $('<td id="defaultloglevel" class="' + ip + '"></td>');
var prfsmth = $('<td id="preferedsmithers" class="' + ip + '"></td>');
var lastseen = x.item(i).getElementsByTagName("lastseen")[0].childNodes[0].nodeValue;
var name = x.item(i).getElementsByTagName("name")[0].childNodes[0].nodeValue;
var status = x.item(i).getElementsByTagName("status")[0].childNodes[0].nodeValue;
var defaultloglevel = x.item(i).getElementsByTagName("defaultloglevel")[0].childNodes[0].nodeValue;
var preferedsmithers = x.item(i).getElementsByTagName("preferedsmithers")[0].childNodes[0].nodeValue;
nm.html(name);
id.html(ip);
st.html(status);
ls.html(lastseen);
dblvl.html(defaultloglevel);
prfsmth.html(preferedsmithers);
row.append(nm);
row.append(id);
row.append(st);
row.append(ls);
row.append(prfsmth);
row.append(dblvl);
body.append(row);
}
table.append(body);
$('#service_table').append(table);
//initiating the editable datatable
var oTable = $('#mytable').dataTable().makeEditable({
sUpdateURL: function(value, settings) {
return (value); //Simulation of server-side response using a callback function
},
"aoColumns": [
{
indicator: 'Saving platforms...',
tooltip: 'Click to edit platforms',
type: 'textarea',
submit: 'Save changes',
fnOnCellUpdated: function(sStatus, sValue, settings) {
alert("(Cell Callback): Cell is updated with value " + sName);
}},
null
,
{
indicator: 'Saving platforms...',
tooltip: 'Click to edit platforms',
type: 'textarea',
submit: 'Save changes',
fnOnCellUpdated: function(sStatus, sValue, settings) {
//I WANT HERE TO BE ABLE TO ALERT() THE ID AND THE CLASS OF THE CELL THAT WAS JUST EDITED
alert("(Cell Callback): Cell is updated with value " + sValue);
}},
null
,
{
indicator: 'Saving platforms...',
tooltip: 'Click to edit platforms',
type: 'textarea',
submit: 'Save changes',
fnOnCellUpdated: function(sStatus, sValue, settings) {
alert("(Cell Callback): Cell is updated with value " + sValue);
}},
{
indicator: 'Saving platforms...',
tooltip: 'Click to edit platforms',
type: 'textarea',
submit: 'Save changes',
fnOnCellUpdated: function(sStatus, sValue, settings) {
alert("(Cell Callback): Cell is updated with value " + sValue);
}}
]
});