[jQuery]如何获得相对于按钮的文本框值?
点击.button-action
会触发该事件$(this).closest(".dmsInput").find('.d').val();
结构如下:
<td class="dmsInput">
<input type="text" maxlength="4" size="4" class="d">
</td>
<td>
<button class="button-action add">+</button>
</td>
我试图提醒值,但它返回undefined。我做得对吗?
答案 0 :(得分:4)
这是因为.closest()将搜索祖先树,但dmsInput
元素不是按钮元素的祖先。
$(this).parent().prev(".dmsInput").find('.d').val();
或
$(this).closest('tr').find('.dmsInput .d').val();