简体   繁体   English

从表的最近一行中查找textarea的值

[英]Find Value of textarea from closest row of table

I have a button Update in One td I want to fetch value of both textarea of td from same tr. 我在一个td中有一个更新按钮,我想从同一tr提取td的两个textarea的值。 There are lots of tr so I have to use closest() method to find element. 有很多tr,因此我必须使用closest()方法来查找元素。 I have tried to find element but it's not working. 我试图找到元素,但是它不起作用。

HTML :- HTML:-

<tr>
    <td>
        <div class="agenda-date">
            <div class="dayofmonth color_font_date">2017-05-31</div>
            <div class="dayofweek">
                Wednesday                                            
            </div>
        </div>
    </td>
    <td>
        <div class="row margin_two_planner">
            <button type="button" class="btn btn-sm btn-primary">AM </button> 
            <a data-toggle="modal" href="#add_apt_status" class=""><input type="number" value="3" name="" class="number_planner"></a>
            <label class="control-label"> 6 </label>
        </div>
        <div class="row margin_two_planner">
            <button type="button" class="btn btn-sm btn-primary">PM </button> 
            <a data-toggle="modal" href="#add_apt_status" class=""><input type="number" value="4" name="" class="number_planner"></a>
            <label class="control-label"> 2 </label>
        </div>
    </td>
    <td style="width: 20%;"> 
            <textarea id="" class="form-control initial_cap appointment_note" required="required" rows="3" name="appointment_note" cols="50" aria-required="true" disabled=""> APT -1 </textarea>
    </td>
    <td style="width: 20%;"> 
        <textarea id="" class="form-control initial_cap holiday_note" required="required" rows="3" name="holiday_note" cols="50" aria-required="true" disabled=""> Holiday - 1 </textarea>
    </td>
    <td>
        <div class="text-right">
            <button type="button" id="" class="btn btn-primary appointment_edit_button">Edit </button>
            <button type="button" id="" onclick="planner_note_edit(1)" class="btn btn-md btn-primary appointment_update_button" style="display:none"> Update </button>
            <button type="button" id="" class="btn btn-md btn-cancel appointment_cancel_button" style="display:none">Cancel </button>
        </div>
    </td>
</tr>

Jquery :- jQuery的:-

function planner_note_edit(planner_note_id)
{

        appointment_note = $(this).closest('td').find(".holiday_note").val();
        alert(appointment_note);
}

But I'm not able to fetch value of textarea from closest td. 但是我无法从最近的td获取textarea的值。

You should get the textarea from current row . 您应该从当前row获取textarea

So, please use .closest('tr') 因此,请使用.closest('tr')

appointment_note = $(this).closest('tr').find(".holiday_note").val();

Also, you have to pass the clicked button object. 同样,您必须传递clicked按钮对象。 this in your function is a reference to the window object. this在您的函数中是对window对象的引用。

function planner_note_edit(planner_note_id,event)
{

    appointment_note = $(event.target).closest('td').find(".holiday_note").val();
    alert(appointment_note);
}

HTML HTML

<button type="button" id="" onclick="planner_note_edit(1,event)" class="btn btn-md btn-primary appointment_update_button" style="display:none"> Update </button>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM