下午好。
我正在开发一些javascript代码,但是有问题。我正在尝试获得两个数量,以总计一个输入。
基本上,这个想法是,当您放置“ Brujas y brujos”和“ Nivel nato”,然后放置“ +5 MAG”而不是“ Magia”中的仅+5时,之前的值(在这种情况下为10),保留15。因此,对于所有STATS,即“ Fuerza”,“ Magia”,“ Resistencia”,“ Velocidad”和“ Vitalidad”。
我暂时离开做的事:
std::unordered_map::operator[]
// stats i
$('.raza,.nivel').on('change', function() {
const raza = $('.raza').val(); // Should return a key for the race, like 'brujas'
const nivel = $('.nivel').val(); // Should return an index for the level, like '0'
const stat = stats[raza]; // Get the race from stats
// Set all stat values
$('.fue').val(stat.fue[nivel]);
$('.mag').val(stat.mag[nivel]);
$('.res').val(stat.res[nivel]);
$('.vel').val(stat.vel[nivel]);
$('.vit').val(stat.vit[nivel]);
});
// stats ii
// Object with all races and levels
const stats = {
// Create object for each race
brujas: {
// An array of values for each level for each stat
fue: [6, 8, 10, 12],
mag: [10, 20, 30, 40],
res: [2, 4, 6 , 8],
vel: [2, 3, 4 , 5],
vit: [55, 65, 80, 90],
},
eva: {
fue: [7, 9, 11, 13],
mag: [0, 0, 0, 0],
res: [3, 5, 7 , 9],
vel: [2, 3, 4 , 5],
vit: [50, 60, 70, 85],
},
humanos: {
fue: [7, 9, 11, 13],
mag: [0, 0, 0, 0],
res: [2, 4, 6 , 8],
vel: [1, 2, 3 , 4],
vit: [35, 45, 55, 65],
},
licantropos: {
fue: [7, 9, 11, 13],
mag: [0, 0, 0, 0],
res: [3, 5, 7 , 9],
vel: [3, 4, 5 , 6],
vit: [55, 65, 80, 90],
},
sirenas: {
fue: [6, 8, 10, 12],
mag: [0, 0, 0, 0],
res: [2, 4, 6 , 8],
vel: [3, 4, 5 , 6],
vit: [55, 65, 80, 90],
},
vampiros: {
fue: [14, 18, 22, 26],
mag: [0, 0, 0, 0],
res: [6, 8, 10 , 12],
vel: [5, 6, 7 , 8],
vit: [85, 100, 115, 130],
},
};
// puntos de stats por nivel
$(document).ready(function() {
$('.nivel').on('change', function() {
var value = this.value;
if (value == '0') {
$('.ps').val('10');
}
if (value == '1') {
$('.ps').val('20');
}
if (value == '2') {
$('.ps').val('30');
}
if (value == '3') {
$('.ps').val('40');
}
$('.ps').change();
});
$('.select').on("change", function() {
var total = 0;
$('.select').each(function() {
var price = parseFloat($(this).find("option:selected").data("price"));
console.log(price);
total += price;
});
$("#opt_price").val(total.toFixed(0))
.change(); // Trigger
});
});
// suma de stats
//fuerza
function updateFuerzaInputValue(){
//Get the input value
var inputValue = document.getElementById("fuerzaselect").value;
//Update the input value in the input box
document.getElementById("fue").value = inputValue;
}
//magia
function updateMagiaInputValue(){
//Get the input value
var inputValue = document.getElementById("magiaselect").value;
//Update the input value in the input box
document.getElementById("mag").value = inputValue
}
//resistencia
function updateResistenciaInputValue(){
//Get the input value
var inputValue = document.getElementById("resistenciaselect").value;
//Update the input value in the input box
document.getElementById("res").value = inputValue
}
//velocidad
function updateVelocidadInputValue(){
//Get the input value
var inputValue = document.getElementById("velocidadselect").value;
//Update the input value in the input box
document.getElementById("vel").value = inputValue
}
//vitalidad
function updateVitalidadInputValue(){
//Get the input value
var inputValue = document.getElementById("vitalidadselect").value;
//Update the input value in the input box
document.getElementById("vit").value = inputValue
}
// suma de stats final
///// fuerza
$(".fuea2, .fueb2").on("keydown keyup change", function(event) { // <--- Respond to change event, too
var tr = $(this).closest("fuetr"); //we will use this to restrict scope to the current table row
tr.find(".fuec2").val(Number(tr.find(".fuea2").val()) + Number(tr.find(".fueb2").val()));
});
我该怎么办?