0
讓我解釋什麼,我嘗試做一個表單,用戶可以把輸入和數據的時間(MM:SS)在一個特定的輸入,例如:總和分鐘,並在通用輸入的Jquery秒
<table border="0" cellpadding="0" cellspacing="0" id='tiempos_te'>
<tr>
<td title="Debe ser 8 dígitos numéricos máximo"><p align="center">Nro. Factura</p></td>
<td title="Debe colocar el tiempo en formato MINSEC (el campo colocara automaticamente los ":")"><p align="center">Montar té</p></td>
<td title="Debe colocar el tiempo en formato MINSEC (el campo colocara automaticamente los ":")"><p align="center">Armado del vaso</p></td>
<td title="Debe colocar el tiempo en formato MINSEC (el campo colocara automaticamente los ":")"><p align="center">Armado del té</p></td>
<td><p align="center">Tiempo total</p></td>
<td><p align="center">Turno</p></td>
</tr>
<tr>
<td><input name="fac1" type="text" id="fac1" onKeyPress="return acceptNum(event)" maxlength="10" class="obligatorio" /></td>
<td> <input type="text" name="tiempo11" id="tiempo11" class="obligatorio tiempo" maxlength="6" onKeyPress="return acceptNum(event)" /></td>
<td> <input type="text" name="tiempo12" id="tiempo12" class="obligatorio tiempo" maxlength="6" onKeyPress="return acceptNum(event)" /></td>
<td> <input type="text" name="tiempo13" id="tiempo13" class="obligatorio tiempo" maxlength="6" onKeyPress="return acceptNum(event)" /></td>
<td><input type="text" name="totalt1" id="totalt1" readonly="readonly" class="total_tiempo" /></td>
<td><select name="turn1" id="turn1" class="obligatorio">
<option value="2">Vespertino</option>
<option value="3">Nocturno</option>
</select></td>
</tr>
</table>
有3個輸入,人們必須輸入時間(mm:ss),並在名爲「totalt1」的輸入中,我需要查看所有輸入的總和(時間)。
我提出(與anothers的幫助)的功能,使之和,但他不隨時間格式工作:
$('#tiempos_te').delegate('input[name^="tiempo"]', 'blur', function() {
var number= this.name.replace('tiempo',''), // extract the number from tiempoxxx
counter = number.substr(0, number.length -1); // keep everything from the number except the last digit
$('input[name^="totalt' + counter + '"]').val($('input[name^="tiempo' + counter + '"]').sumValues());
});
代碼添加或刪除輸入:
var counter = 1;
$("#addButton").click(function() {
//alert (counter);
if(counter>=6){
alert("Solo se permiten 6 Mediciones por dia");
return false;}
else{
counter++;
$('#tiempos_te').append('<tr id="terow' + counter + '">' +
'<td><input name="fac' + counter + '" type="text" id="fac' + counter + '" onKeyPress="return acceptNum(event)" maxlength="10" class="obligatorio"/></td>' +
'<td> <input type="text" name="tiempo' + counter + '1" id="tiempo' + counter + '1" class="obligatorio tiempo" maxlength="6" onKeyPress="return acceptNum(event)" /></td>' +
'<td> <input type="text" name="tiempo' + counter + '2" id="tiempo' + counter + '2" class="obligatorio tiempo" maxlength="6" onKeyPress="return acceptNum(event)" /></td>' +
'<td> <input type="text" name="tiempo' + counter + '3" id="tiempo' + counter + '3" class="obligatorio tiempo" maxlength="6" onKeyPress="return acceptNum(event)" /></td>' +
'<td><input type="text" name="totalt' + counter + '" id="totalt' + counter + '" readonly="readonly" class="total_tiempo" /></td>' +
'<td><select name="turn' + counter + '" id="turn' + counter + '" class="obligatorio">' +
'<option value="2">Vespertino</option>' +
'<option value="3">Nocturno</option>' +
'</select></td>' +
'</tr>');}
});
$("#delButton").click(function() {
if(counter<=1){
alert("Debe existir mínimo 1 Registro");
return false;}
else{
$('#terow' + counter).remove();
counter--;}
});
示例代碼:http://jsfiddle.net/JuJoGuAl/tNjf3/