[英]Load image from datatable to a modal when I click on a row
我有一個表,其中有些行包含這樣的圖像
<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`。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.