Javascript-форум (https://javascript.ru/forum/)
-   Элементы интерфейса (https://javascript.ru/forum/dom-window/)
-   -   Помогите делегировать событие (https://javascript.ru/forum/dom-window/47150-pomogite-delegirovat-sobytie.html)

icehummer 11.05.2014 12:25

Помогите делегировать событие
 
<span id="count_detail"><input name="count" id="count" type="hidden" value="1"></span>
<table width="100%" border="1">
<tbody id="detail_list">
<tr>
<th scope='col' style="width:20px;">№</th>
<th scope='col'>Наименование деталей</th>
<th scope='col' style="width:40px">Кол.</th>
<th scope='col' style="width:100px">Признак</th>
<th scope='col' style="width:50px">Цена</th>
<th scope='col' style="width:100px">Н/ч ремонта</th>
<th scope='col' style="width:100px">Н/ч окраски</th>
<th scope='col' style="width:31px">...</th>
</tr>
<tr>
<th scope='col'><input name='detail_num_1' type='text' style='border:none; outline:none; width:100%; text-align:center' value='1' readonly='readonly'></th>
<th scope='col'><input name='detail_name_1' type='text' style='border:none; outline:none; width:100%;'></th>
<th scope='col'><input name='detail_con_1' type='text' style='border:none; outline:none; width:100%; text-align:right'></th>
<th scope='col'><input name='detail_based_1' type='text' style='border:none; outline:none; width:100%;'></th>
<th scope='col'><input name='detail_prices_1' type='text' style='border:none; outline:none; width:100%; text-align:right;'></th>
<th scope='col'><input name='detail_repair_1' type='text' style='border:none; outline:none; width:100%;'></th>
<th scope='col'><input name='detail_paint_1' type='text' style='border:none; outline:none; width:100%;'></th>
<th scope='col'><input type="button" value="..."/></th>
</tr>
</tbody>
</table>
Я на JavaScript добавляю новые строки в таблицу, а вот событие не могу на повесить на кнопку.
Нужно что бы по нажатию на буттон совершалось WinOpen('500', '275', ''), но нужно сделать через делегирование, что то на вроде этогоЖ
<script>
document.getElementById('detail_win').onclick = function(e) {
var target = e && e.target || event.srcElement;

if (target.nodeName != 'A') return;

var href = target.getAttribute('href');
alert(href);

return false // prevent url change
};
</script>
ну это я взял с этого же сайта из учебных материалов, а вот под ской код переделать не могу...

ruslan_mart 11.05.2014 19:18

document.getElementById('detail_list').onclick = function(e) {
    var target = e && e.target || window.event.srcElement;
    if(target.tagName == 'INPUT' && target.type == 'button') {
        WinOpen('500', '275', '');
    }
}

icehummer 12.05.2014 02:40

Отлично работает!! Большое спасибо! +


Часовой пояс GMT +3, время: 08:24.