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

时间:2017-06-02 11:49:09

标签: javascript php jquery html

我有一个按钮Update in One td我想从同一个tr中获取td的textarea值。 有很多tr所以我必须使用closest()方法来查找元素。我试图找到元素,但它不起作用。

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: -

function planner_note_edit(planner_note_id)
{

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

但是我无法从最近的td获取textarea的值。

1 个答案:

答案 0 :(得分:2)

您应该从当前m获得res

所以,请使用textarea

row

此外,您必须传递.closest('tr')按钮对象。函数中的appointment_note = $(this).closest('tr').find(".holiday_note").val(); 是对clicked对象的引用。

this

HTML

window