JQuery访问输入值

时间:2014-04-11 12:14:55

标签: jquery

如何在点击#first时访问位于#second.glyphicon-pencil的输入框的相应值,即当我点击.glyphicon时它必须给出值90909 -pencil on <tr>此处和1000125点击第二个<tr>

<tr id_gl_code="66" class="success">
     <td id="first" id_gl_code="66"><input type="text" class="form-control" value="90909"></td>
     <td id="second"><input type="text" class="form-control" value="some xyz"></td>
     <td id="third"><span id_gl_code="66" class="glyphicon glyphicon-pencil"></span></td>
     <td id="fourth"><span id_gl_code="66" class="glyphicon glyphicon-trash"></span></td>
</tr>

<tr id_gl_code="67" class="success">
     <td id="first"><input type="text" class="form-control" value="1000125"></td>
     <td id="second"><input type="text" class="form-control" value="miscellanious income expenses"></td>
     <td id="third"><span  id_gl_code="67" class="glyphicon glyphicon-pencil"></span></td>
     <td id="fourth"><span  id_gl_code="67" class="glyphicon glyphicon-trash"></span></td>
</tr>

1 个答案:

答案 0 :(得分:0)

试试这个

$(document).on('click','.glyphicon-pencil',function(){
var first=$(this).parents('tr').find('td:eq(0) input').val()
var second=$(this).parents('tr').find('td:eq(1) input').val()
});

DEMO