我有一个表格,其中包含一些包含此类图像的行
<tr>
<td><img src="img/examples/photo/example_1s.jpg" class="img-polaroid"/></td>
<td>jhon</td>
<td>mv03790</td>
</tr>
我正在尝试使用行中的数据加载模态,
喜欢这个
$('tr td').on('click',function(){
$("#fname").val($(this).closest('tr').children()[1].textContent);
$("#username").val($(this).closest('tr').children()[2].textContent);
$("#rowmodal").modal("show");
});
它适用于所有文本,但我无法加载图像
这是模态
<img id="edit_foto" src="">
<input type="text" id ="fname"/>
<input type="text" id ="username"/>
我正在尝试像用户编辑模态一样,当我从表中单击用户时加载数据
对于图像,请尝试以下操作:
$('tr:has(td)').on('click', function() {
var $row = $(this);
$("#fname").val($row.children()[1].textContent);
$('#edit_foto').attr('src', $row.find('img').attr('src'));
$("#username").val($row.children()[2].textContent);
$("#rowmodal").modal("show");
});
我将单击处理程序移动到<tr>
,因为它与单击任何and simplifies
$row相同"