无法访问输入值

时间:2013-05-20 20:47:59

标签: jquery twitter-bootstrap html-table

我有一个带有表格的网页来输入数据。添加/删除行有效,但添加的行会复制第一行的数据。 我正在使用:

jquery
bootstrap  
globalize    
jquery.dataTables
query.table.addrow

我无法访问数值。我想:

  1. 为输入提供默认值0。
  2. 获取值并使用它们来计算页面中的其他值。
  3. html:

              <form class="form-horizontal">
                <table id="tabc" border="1"  cellpadding="0" cellspacing="0" class="table table-condensed datatable" style="width:auto;margin:30px">
                  <thead>
                    <tr>
                      <th title="Masa en gramos" >Masa(g)</th>
                      <th>Analito</th>
                      <th title="Concentración del standard">Std</th> 
                      <th>Volumen</th>
                      <th></th>
                    </tr>
                  </thead>
                  <tbody>
                    <tr>
                      <td><input type="number" class="input-mini" name="ryacur" id="ryacur1" ></td>
                      <td><input type="text" data-provide="typeahead" data-source='["Ag","Al","As","Au","Ba","Be","Bi","Br","Cr","Pb","Pd"]' autocomplete="off" class="input-mini" name="anacur" id="anacur1" ></td>
                      <td><input type="number" class="input-mini" name="stdcur" id="stdcur1" ></td>
                      <td></td>
                      <td><input type="button" class="AddNew" value="Agrega"></td>
                    </tr>
                  </tbody>
                </table>
                 <div class="span2 offset3"><input type="submit" name="enviar" value="Enviar" style="color:darkblue"></div>
              </form>
    

    js:

    $('#tabc').dataTable({
        "oLanguage": {
            "sUrl": "/arch/es_CL.js"
        },
            "bPaginate": false,
            "bLengthChange": false,
            "bFilter": false,
            "bSort": false,
            "bInfo": false,
            "bAutoWidth": true
    });
    
    
    $('.AddNew').click(function () {
        var row = $('#tabc tbody tr:last-child'),
            newRow = row.clone(),
            oTable = $('#tabc').dataTable();
        newRow.find("input", newRow).each(function () {
            this.val = '';
            var num = +(this.id.match(/\d+$/) || [0])[0] + 1
            this.id = this.id.replace(/\d+$/, "") + num;
            console.log(this.val); // <<<<<<<<<<< Doesn't work
            $('input[type="button"]', newRow).removeClass('AddNew').addClass('RemoveRow').val('Borra');
        });
        newRow.insertAfter(row);
    });
    
    $('table').on('click', '.RemoveRow', function () {
        $(this).closest('tr').remove();
    });
    

    我错过了什么?

1 个答案:

答案 0 :(得分:0)

将此console.log(this.val);更改为

console.log(this.value);console.log($(this).val());