获取div输入的childs值

我正在尝试从一组div上包含的三个输入中获取值,但只有不属于这些的ediv invisible-age-range-row


<div class="row">

  <div class="col-md-7 col-xs-12 dist-element-row">

    <label>Franjas de edad</label>

    <div class="row age-range-row">

      <div class="col-md-2">

        <label>Desde</label>

        <input type="number" min="0" class="form-control from" value="1">

      </div>

      <div class="col-md-2">

        <label>Hasta</label>

        <input type="number" min="0" class="form-control to" value="2">

      </div>

      <div class="col-md-2">

        <label>%</label>

        <input type="number" min="0" max="100" class="form-control percentage" value="20">

      </div>

      <div class="col-md-6 options-cell">

        <button class="btn btn-primary add-range">+</button>

        <button class="btn btn-default delete-range">-</button>

      </div>

   

我这样得到的div


var ranges = $('.age-range-row').not('.invisible-age-range-row');

但是我不能以这种方式访问输入值:


ranges.each(function(range) {

    var elements = [];

    console.log(range);

    elements.push(range.find('.from'));

    elements.push(range.find('.to'));

    elements.push(range.find('.percentage'));

    stored_ranges.push(elements);

});

     

白衣染霜花
浏览 141回答 3
3回答

大话西游666

每个函数的第一个参数指的是元素的索引。您需要使用range作为第二个元素才能用作元素选择器:&nbsp; ranges.each(function(index,range){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var elements = [];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;console.log(range);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;elements.push(range.find('.from'));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;elements.push(range.find('.to'));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;elements.push(range.find('.percentage'));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;stored_ranges.push(elements);&nbsp; &nbsp; &nbsp; &nbsp;});
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript