嗨,我有以下
HTML:
<p>
<input type="text" name="field1"/> <input type="hidden" name="fieldh1"/>
<button type="button" class="sendInfo">Send</button>
</p>
<p>
<input type="text" name="field2" /> <input type="hidden" name="fieldh2"/>
<button type="button" class="sendInfo">Send</button>
</p>
我想要的是当用户点击按钮时,我需要使用ajax发送字段字段的内容.
这就是我正在努力做的事,但没有成功.
$(function() {
$('button.sendInfo').live('click',function() {
var id = $(this).parent().next('[type=text]').val();
alert(id);
});
});
我计划将用户在文本框中键入的内容设置为隐藏字段,并将从ajax调用中接收的值设置为普通文本框.但问题是,我甚至无法获得与用户点击的按钮位于同一行的文本框的值.
谁能帮我?
非常感谢.
解决方法
尝试:
$(this).siblings('input:text').val();
或者在下面找到:
$(this).parent().find('[type=text]').val();
接下来只搜索紧随其后的兄弟姐妹.