0

Есть таблица. Нужно по клику на строку получить текст ячейки class="item".

jQuery:

$('tbody#t_price >tr').on('click', '.rowlink', function() {
  var it = $(this).children('td').find('.item').html();
        console.log(it);
});

HTML

<table>
    <thead>
        <tr>
            <th rowspan="2"></th>
            <th rowspan="2">Номенклатура</th>
            <th rowspan="2">Ед.Изм.</th>
            <th rowspan="2">Мин(грн)</th>
            <th colspan="2">Тип</th>
        </tr>
        <tr>
            <th>ГРН</th>
            <th>ДОЛ</th>
        </tr>
    </thead>
        <tbody id="t_price">
            <tr class="rowlink">
               <td>1</td>
               <td class="item">Кофе1</td>
               <td class="unit">кг</td>
               <td>300</td>
               <td>400</td>
               <td>500</td>
          </tr>
          <tr  class="rowlink">
             <td>2</td>
             <td class="item">Кофе2</td>
             <td class="unit">уп</td>
             <td>350</td>
             <td>470</td>
             <td>600</td>
          </tr>
          <tr  class="rowlink">
            <td>3</td>
            <td class="item">Кофе3</td>
            <td class="unit">г</td>
            <td>110</td>
            <td>200</td>
            <td>350</td>
          </tr>
        </tbody>
 </table>

2 ответа 2

1

$(function(){
  $('#t_price').on('click', '.rowlink', function(){
    alert($(this).find('.item').html());
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
    <thead>
        <tr>
            <th rowspan="2"></th>
            <th rowspan="2">Номенклатура</th>
            <th rowspan="2">Ед.Изм.</th>
            <th rowspan="2">Мин(грн)</th>
            <th colspan="2">Тип</th>
        </tr>
        <tr>
            <th>ГРН</th>
            <th>ДОЛ</th>
        </tr>
    </thead>
        <tbody id="t_price">
            <tr class="rowlink">
               <td>1</td>
               <td class="item">Кофе1</td>
               <td class="unit">кг</td>
               <td>300</td>
               <td>400</td>
               <td>500</td>
          </tr>
          <tr  class="rowlink">
             <td>2</td>
             <td class="item">Кофе2</td>
             <td class="unit">уп</td>
             <td>350</td>
             <td>470</td>
             <td>600</td>
          </tr>
          <tr  class="rowlink">
            <td>3</td>
            <td class="item">Кофе3</td>
            <td class="unit">г</td>
            <td>110</td>
            <td>200</td>
            <td>350</td>
          </tr>
        </tbody>
 </table>

1

Решение:

http://codepen.io/anon/pen/XXjYyN

$(document).on('click', '#t_price>.rowlink', function() {
  var it = $(this).find('.item').text();
  alert(it);
});

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.