我有两个表,第一个(id =符号)包含3个图像。 第二个表(id = tbl)将包含各种不同的图像。
我正在尝试使用从符号表中选择的单元格替换单元格的图像(对于此示例,可以说是顶行右侧的第二个单元格)。
我想在悬停在符号表上时突出显示符号表中的图像。 单击时,我想用单击的图像替换另一个表中的图像,并更改包含所选图像的表格单元格的背景颜色。 我还需要能够识别单击的图像(或单元格)。
这是我当前的小提琴不能很好地运作http://jsfiddle.net/bLb3H/70/。
感谢您的帮助。
<table id="symbols">
<tr>
<td ><img src="http://icons.iconarchive.com/icons/deleket/soft-scraps/32/Button-Blank-Yellow-icon.png"/></td>
<td >
<img src=" http://icons.iconarchive.com/icons/deleket/soft-scraps/32/Button-Blank-Blue-icon.png"/>
</td>
<td class="items p1 p3"><img src="http://icons.iconarchive.com/icons/yootheme/social-bookmark/32/social-google-buzz-button-icon.png"/></td>
</tr>
</table>
<table border="1" id="tbl">
<tr>
<td ></td>
<td bgcolor=#000000 >
<img src="http://icons.iconarchive.com/icons/deleket/soft-scraps/32/Button-Blank-Red-icon.png"/>
</td>
<td class="items p1 p3"></td>
</tr>
<tr>
<td bgcolor=#000000 ></td>
<td class="items p1"></td>
<td class="items p3" bgcolor=#000000 ></td>
</tr>
<tr>
<td class="piece" id="p1" ></td>
<td bgcolor=#000000 ></td>
<td class="piece" id="p3" ></td>
</tr>
</table>
jquery的
var imgs = $('img');
imgs.click(function () {
var img = $(this);
$("#tbl").find("tbody tr").eq(2).children().first().attr('src', img);
});
答案 0 :(得分:0)
这是一种方式.. http://jsfiddle.net/4Ym43/
var imgs = $('img');
imgs.click(function(){
var img = $(this);
$("#tbl").find("tbody tr:eq(0) td:eq(1) img").attr('src', img.attr('src'));
//The cells we can move our image to.
});
虽然我宁愿使用id或类