2013-05-20 75 views
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(); 
}); 

我缺少什麼?

回答

0

改變這個console.log(this.val);

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

+0

TNX,它的工作。那麼它什麼時候值呢? –

+1

'value'是DOM屬性,而'.val()'是jquery方法,所以你不能使用'this.val()'或'$(this).value' ..因爲'this'表示DOM元素, $(this)'代表jQuery對象 –

+0

明白了......終於。 –