我想获得输入的值。在我的应用程序中,我想更新数据库中每行的条目。所以,当我点击按钮时,我想要相应行的值。
$('.ajouter_un_sol').click(function(){
var id_sol = $(this).find('.nom_sol').value;
alert(id_sol);
});
我为你做了一个jsfiddle,看看我想做什么。我试图获得一行的价值。
有人可以告诉我应该怎么做吗?
答案 0 :(得分:0)
尝试
var id_sol = $(this).closest("tr").find('.nom_sol').val()
.value
是一个javscript属性,因此您需要使用.val()
。
您正试图find
input
button
内td
但实际上它在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();
答案 2 :(得分:0)
使用此
$('.button').click(function(){
var age = $(this).parent().parent().children('td').find('.age').val();
alert(age);
})
答案 3 :(得分:0)
在你的小提琴中,而不是
&#xA;&#xA; 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;