使用jQuery获取"this"输入框的值? [英] Get the value of 'this' input box with jQuery?

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

问题描述

因此,我有多个div,其中包含相同的HTML结构,类名和属性.除了输出的内容外,它们完全相同.每个div内都有一个具有相同类的输入框.如何获得每个输入框的特定值?我猜想我会使用'this',但是我无法弄清楚如何确切地使用'this'来获取每个文本框的特定值.我不想使用每个,因为这会输出一个值数组.

So I have multiple div containing same HTML structure, class names, and attributes. They are identical except the content it outputs. Each div has an input box within with the same class. How do I get the specific value of each input box? I am guessing I would use 'this' but I cannot figure out how to exactly use 'this' to get the specific value of each text box. I don't want to use each because that outputs an array of values.

<div>
    <input class="player-input" type="text"></input>
    <button class="enter">Enter</button>
    <p>Lorem Ipsum<p>
</div>

<div>
    <input class="player-input" type="text"></input>
    <button class="enter">Enter</button>
    <p>Lorem Ipsum<p>
</div>

我正在使用Meteorjs,事件设置如下:

I am using Meteorjs and events are set up like so:

Template.players.events({
    'click .enter': function(){
          //code
    },
    'keydown .player-input': function(e){
        if (e.which == 13){
            //code
        }
    }
});

如何使用jQuery获取每个特定输入元素的值?

How would I get the value of each specific input element with jQuery?

推荐答案

这是我将每个段落附加到段落的方式,让我知道它是否有效: http://jsfiddle.net/VtMRx/

Here's how I appended each to paragraph, let me know if it works: http://jsfiddle.net/VtMRx/

$(".player-input").each(function() {
    //alert(this.value);
    $("#paragraphID").append(this.value + "<br/>");
});

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

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