Py学习  »  Jquery

jquery count具有值的输入字段数

Sam • 5 年前 • 1996 次点击  

在输入字段中输入值时,我想计算有多少个输入字段 在那一排 总共有一个值。

<div class="row">
    <input type="text" class="input input1" />
    <input type="text" class="input input2" />
    <input type="text" class="input input2" />
</div>

<div class="row">
    <input type="text" class="input input1" />
    <input type="text" class="input input2" />
    <input type="text" class="input input2" />
</div>

我在试着跟踪,但我认为问题出在循环上。

$('.input').keyup(function () {

    var field = $(this).parent().children('.input');
    var count = 0;

    $(field).each(function (i) {
        var len = $(field).val().length;        
        if (len > 0 ) {
            count++;
        }
    });

  alert(count);

});

jsfiddle公司 链接: http://jsfiddle.net/18cpotw6/

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/48122
 
1996 次点击  
文章 [ 4 ]  |  最新文章 5 年前