-
-
Save Lvcios/477ebcb80cc2c7be5ab630caad55e862 to your computer and use it in GitHub Desktop.
Ejemplo multiplicación dinámica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<style> | |
</style> | |
<body> | |
<table id="tablaFrus"> | |
<thead> | |
<tr> | |
<th>Peso</th> | |
<th>Piezas</th> | |
<th>Total</th> | |
</tr> | |
</thead> | |
<tbody> | |
</tbody> | |
</table> | |
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> | |
<script> | |
//la llamada ajax retorna un objeto similar: | |
var arr = [ | |
{ part_number:1, fru_weiIght : 1.82 }, | |
{ part_number:2, fru_weiIght : 2.82 }, | |
{ part_number:3, fru_weiIght : 4.82 }, | |
{ part_number:4, fru_weiIght : 3.82 }, | |
] | |
arr.forEach(function(item, index){ | |
var str = "<tr>"; | |
str += "<td>" + item.fru_weiIght +"</td>" | |
str += "<td><input class='inputable' data-part_number='" + item.part_number +"' data-fru_weiIght='" + item.fru_weiIght + "'/></td>" | |
str += "<td><label data-part_number='" + item.part_number +"'>Resultado</label></td>" | |
str += "</tr>" | |
$("#tablaFrus").find("tbody").append(str) | |
}) | |
$( ".inputable" ).on( "change", function() { | |
var peso = $(this).attr("data-fru_weiIght"); | |
var part = $(this).attr("data-part_number"); | |
var resultado = $(this).val() * peso; | |
$("label[data-part_number = '" + part +"']").text(resultado) | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment