jQuery获取先前的输入文本 [英] jquery get previous input text

查看:82
本文介绍了jQuery获取先前的输入文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下html:

    <div class="active_string">
                <input type="text" class="answer" /><div class="images"><img src="/images/myImage.png" alt="" /></div>
                <a href="" class="check_quest" id="1">Click me</a>
</div>
    <div class="active_string">
                <input type="text" class="answer" /><div class="images"><img src="/images/myImage.png" alt="" /></div>
                <a href="" class="check_quest" id="2">Click me</a>
</div>

对于check_quest的每次单击,我想获得相应输入的值.我该如何使用查询.我尝试了以下方法:

For every click on check_quest I want to get value of a corresponding input. How can I do it using query. I`ve tried the following:

$(this).prev().prev().text()

但是prev text()和val的这一组合和其他组合未显示Ive放入该文本字段中的文本.

but this one and other combinations of prev text() and val are not showing the text Ive put into that textfield.

推荐答案

您是否尝试过$(this).prev('input')?

我的意思是:$(this).prevAll('input').val().

这篇关于jQuery获取先前的输入文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆