0

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

jquery
bootstrap  
globalize    
jquery.dataTables
query.table.addrow

我无法访问数值。我想要:

  1. 为输入的数字指定默认值 0。
  2. 获取值并使用它们来计算页面中的其他值。

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

我错过了什么?

4

1 回答 1

0

将其更改console.log(this.val);

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

于 2013-05-20T20:50:22.110 回答