【发布时间】:2013-06-11 03:44:20
【问题描述】:
如何获取特定行单元格索引的列 ID?
HTML 表格设计:My Table
当表格的单元格内容被放入另一个单元格时,此代码处理和 Ajax 请求:
redipsInit = function () {
// reference to the REDIPS.drag lib
var rd = REDIPS.drag;
// initialization
rd.init();
// dragged elements can be placed to the empty cells only
rd.dropMode = 'single';
// define dropped handler
//the parameter targetCell is the reference of the cell where the content has been
//dropped
rd.event.dropped = function (targetCell) {
var tbl = rd.findParent('TABLE', targetCell); //reference to my table
//getting the tabindex attribute that in my case represent the row index
var cardPosition = targetCell.attributes[0].value;
// the cell content (the div tag with class = "drag t1") has an ID that reprensents
// the content ID in my DB.
var cardIdBeingDragged = targetCell.firstElementChild.id;
var columnID = "";
var parametros = {
"Card_Position": cardPosition,
"Card_ID": cardIdBeingDragged,
"Column_ID" : ??? // still dont know how to get it.
};
$.ajax({
type: 'POST',
url: "../../Contenido/Board.aspx/SaveCardPosition",
data: JSON.stringify(parametros),
contentType: "application/json; charset=utf-8",
dataType: "json"
});
};
};
好的,我会做一个场景来理解我想要什么。
当单元格内容从一个单元格拖放到另一个单元格时,我能够处理上面的 javascript 代码。
下一步是获取 3 个值参数以在代码后面 (ASP.Net) 中发送到我的 webMethod(SaveCardPosition)
我能够获得:
CardId(Cell ContentId)
targetCell 所属的行索引(Card_Position)
但是我不知道如何获取这个targetCell所属的列id。
我怎样才能做到这一点?
【问题讨论】:
-
我认为
targetCell.id应该给出目标单元格ID或者试试$(targetCell).parent().closest('td').attr('id') -
是的 targetCell.id 给了我单元格 ID,但我想要该单元格所属的列 ID。
标签: jquery html asp.net redips.drag