获取上一个单元格的图像

Getting previous cell's image

本文关键字:图像 单元格 上一个 获取      更新时间:2023-09-26

我有两个单元格,我想获取前面的元素图像源。因此,我可以替换该图像网址。

string args =string.Format("'{0}'", tblCell.ID);
A.OnClientClick = String.Format("B({0}); return false;", args);

在 JS 文件中:

function B( cid) {  
$("td[id$='" + cid + "']").css("background-color", colorSelected); // this works
}

但是,我想获取以前的"td"图像并替换该图像,我该怎么办?

我尝试在函数 B 中使用这个(但 ti 在警报时给了我未定义):

var a = $("td[id$='" + cid + "']").closest('td').prev();
alert(a.id);

如果两个单元格在同一行中,则需要省略 .closest('td') 调用,因为 .closest() 向上遍历树(http://api.jquery.com/closest/)。

试试这个:

var a = $("td[id$='" + cid + "']").prev('td');
alert(a.id);