[英]Use same image for link for each row of a table
在一个表中,我在每一行上都有一个删除链接。 我正在尝试添加相同的图像进行链接。 图像仅添加到第一行,而不添加到其余行。 这就是我所做的。
$(document).ready(function () {
$('.isSelected').click(function () {
var pdtname = $(this).attr('data-productname');
if ($(this).prop("checked")) {
$("#result").show();
if ($(".isSelected:checked").length == 2) {
$(".isSelected").not(":checked").prop("disabled",true);
}
var table = $('<table></table>').addClass('tfoo').attr("data-productname", pdtname);
var row = $('<tr></tr>').addClass('rfoo').text(pdtname);
**var link = $("#imgLogo").wrap('<a href="javascript:void(0);"></a>').addClass('lfoo');**
row.append(link);
table.append(row);
$('#result').append(table);
$("#result .lfoo").on('click', function () {
$('input[data-productname="' + $(this).parent().parent().parent().attr("data-productname") + '"]').prop("checked", false);
$(this).parent().parent().parent().remove();
$(".isSelected").not(":checked").prop("disabled",false);
});
} else {
$('table[data-productname="' + pdtname + '"]').remove();
$(".isSelected").not(":checked").prop("disabled",false);
}
});
});
这是图像链接的行var link = $("#imgLogo").wrap('<a href="javascript:void(0);"></a>').addClass('lfoo');
看起来您想要这样的东西: http : //jsfiddle.net/7kk2b5sp/1/
有更好的方法可以改善此问题,但这是另一个问题。 对于您所关心的问题,您想克隆图像并使用class
而不是id
。
变化:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.