How can I get values of inputs that have the same class using JQuery each?

前端 未结 4 1107
灰色年华
灰色年华 2021-01-28 07:32

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).t         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-28 07:47

    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;
    });
    

提交回复
热议问题