使用" .find()"获取特定输入的值

时间:2016-06-16 15:07:18

标签: javascript jquery

我想获得输入的值。在我的应用程序中,我想更新数据库中每行的条目。所以,当我点击按钮时,我想要相应行的值。

$('.ajouter_un_sol').click(function(){
       var id_sol = $(this).find('.nom_sol').value;
        alert(id_sol);
    });

我为你做了一个jsfiddle,看看我想做什么。我试图获得一行的价值。

有人可以告诉我应该怎么做吗?

4 个答案:

答案 0 :(得分:0)

尝试

var id_sol = $(this).closest("tr").find('.nom_sol').val()

.value是一个javscript属性,因此您需要使用.val()

您正试图find input buttontd但实际上它在td内,因此您需要在父{内tr内找到{{1}} {1}}

答案 1 :(得分:0)

在jquery中使用.val()

  

.val()方法主要用于获取表单元素的值   例如input,select和textarea。

var id_sol = $(this).find('.nom_sol').val();

用于您的场景

$(this).parents('tr').find('td .age').val();

Fiddle

答案 2 :(得分:0)

使用此

$('.button').click(function(){
        var age = $(this).parent().parent().children('td').find('.age').val();
    alert(age);
})

答案 3 :(得分:0)

在你的小提琴中,而不是




  var age = $(this).find('。age')。value;&#xA; < / code> 
&#xA;&#xA;

尝试

&#xA;&#xA;
  var age = $(this).closest('tr' ).find('。age')。val();&#xA;  
&#xA;&#xA;

nearest('tr')找到最近的类型'祖先' tr',然后从那里搜索年龄字段。

&#xA;