单击同级选择时的jquery
我从数据库中生成一个表,如下所示单击同级选择时的jquery,jquery,html,onclick,Jquery,Html,Onclick,我从数据库中生成一个表,如下所示 <table id="items"> <thead> <tr> <th>Details</th> <th>Goldmine ID</th> <th> </th> </tr> </thead> <tbody> <tr>
<table id="items">
<thead>
<tr>
<th>Details</th>
<th>Goldmine ID</th>
<th> </th>
</tr>
</thead>
<tbody>
<tr>
<td class="evenrow">This is a test Description generated through UNIT Tests for the category description</td>
<td class="evenrow"><input type="text" value="" id="106" class="gminput"></td>
<td class="butCell evenrow"><button class="saveButton updateitem">Update</button></td>
</tr>
<tr>
<td class="oddrow">This is a test Description generated through UNIT Tests for the category description</td>
<td class="oddrow"><input type="text" value="" id="107" class="gminput"></td>
<td class="butCell oddrow"><button class="saveButton updateitem">Update</button></td>
</tr>
<tr>
<td class="evenrow">This is a test Description generated through UNIT Tests for the category description</td>
<td class="evenrow"><input type="text" value="" id="108" class="gminput"></td>
<td class="butCell oddrow"><button class="saveButton updateitem">Update</button></td>
</tr>
</tbody>
</table>
你想要的元素是
$(this).closest('tr').find('.gminput')
您可以使用
var input = $(this).closest('tr').find('.gminput');
var value = input.val();
var id = input.attr('id');
你想要的元素是
$(this).closest('tr').find('.gminput')
您可以使用
var input = $(this).closest('tr').find('.gminput');
var value = input.val();
var id = input.attr('id');
jQuery中没有方法
forEach()
。。尝试.each()
jQuery中没有方法
forEach()
。。尝试.each()
当按钮
可能就足够时,为什么在正文
上有一个点击事件
为什么要在
正文
上点击事件,而按钮
可能就足够了?我可以把你的问题总结成一句话;)作为旁注,它是。每个@user1534664我个人已经阅读了全文,我希望有足够的信息来确定需要什么。HTML特别有用。我可以把你的问题总结成一句话;)作为旁注,它是。每个@user1534664我个人已经阅读了全文,我希望有足够的信息来确定需要什么。HTML特别有用。我猜
是动态生成的。如果行是动态生成的,仍然会出现问题。我猜
是动态生成的。如果行是动态生成的,仍然会出现问题。是的,我明白了,我写得很快,通常使用C语言我的错误是的,我明白了,我写得很快,通常用C语言写。原谅我的错误
$('.updateitem').on('click', function(){
$elem = $(this).parents('tr').find('.gminput');
var id = $elem.prop('id');
var val = $elem.val()
})