我怎样才能得到有使用每个JQuery的同一类的输入值? [英] How can I get values of inputs that have the same class using JQuery each?

查看:80
本文介绍了我怎样才能得到有使用每个JQuery的同一类的输入值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该很容易,但我似乎无法得到它的权利。

This should be easy, but I can't seem to get it right.

var totalHours = 0;
this.$(".timesheet-daily-input").each( function () {
    var inputValue = $(this).text();
    var hours = parseInt(inputValue);
    totalHours += (hours == null) ? 0 : hours;
});

我试过 $(本).VAL() $(本)。html的()为好,但不能获取值从输入字段。

I've tried $(this).val() and $(this).html() as well, but can't get the values out of the input fields.

编辑:道歉,我知道我忘了提东西。 此。在每个循环的开始是因为我使用的骨干机型和集合。首届这一点。指的是有问题的具体型号。它通过循环的次数适当数量的,我只是不能获得的价值。

Apologies, I knew I was forgetting to mention something. The "this." at the start of the each loop is because I am using backbone's models and collections. The first "this." refers to the specific model in question. It loops through the proper number of times, I just can't get the value.

推荐答案

找不到一个确切的解决方案,但通过选择父分区和循环通过它的子元素改变了我的方法。

Couldn't find an exact solution, but changed my approach by selecting the parent div, and looping through it's child elements.

var totalHours = 0;
this.$("#timesheet-daily-entry-fields-container").children().each(function () {
    var inputValue = $(this).val();
    var hours = parseInt(inputValue);
    totalHours += isNaN(hours) ? 0 : hours;
});

这篇关于我怎样才能得到有使用每个JQuery的同一类的输入值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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