Javascript代码隐藏显示价格*数量以显示总计
我的代码有这个问题,我无法提供我想要的答案。我想为产品选择一个选项,然后为价格选择一个选项,然后输入数量,并让代码交付小计。 问题是,因为我有不同的产品,每个产品有3种不同的价格,我需要我的代码来提供正确的答案 我现在的代码只考虑第一个产品的第一个价格的价值,我似乎无法让它工作,我觉得我几乎有了代码。。。请帮帮我:)Javascript代码隐藏显示价格*数量以显示总计,javascript,store,show-hide,Javascript,Store,Show Hide,我的代码有这个问题,我无法提供我想要的答案。我想为产品选择一个选项,然后为价格选择一个选项,然后输入数量,并让代码交付小计。 问题是,因为我有不同的产品,每个产品有3种不同的价格,我需要我的代码来提供正确的答案 我现在的代码只考虑第一个产品的第一个价格的价值,我似乎无法让它工作,我觉得我几乎有了代码。。。请帮帮我:) 您可以在这些行中尝试一些东西 $(document).ready(function () { // Cache the variables var $eli
您可以在这些行中尝试一些东西
$(document).ready(function () {
// Cache the variables
var $elias = $('#elias'),
$elias1 = $('#elias1'),
$elias2 = $('#elias2'),
$product = $('#producto1'),
$error = $('.error'),
$container = $('.container');
$("td").hide();
var productValue;
$product.change(function () {
$(".e01 td").hide();
$("td." + $(this).val()).show();
// Only show the container when the selections are not first 2
if (this.value !== 'Selecciona' && this.value !== '00') {
$error.addClass('hide');
$container.removeClass('hide');
} else {
$error.removeClass('hide');
$container.addClass('hide');
}
productValue = this.value;
}).change();
// Bind the change event for Dropdowns
var $quantity = $('#CAT_Custom_500436'),
$total = $("#CAT_Custom_500440");
$elias.add($elias1).add($elias2).change( findTotal);
$quantity.keyup(findTotal);
function findTotal() {
// Get the value
var quan = $quantity.val();
var pri = $('.'+ productValue).find('select').val();
var tot = pri * quan;
$total.val(tot);
}
});
非常接近,您有3个价格,但随后将每个价格计算到同一个变量total1中,靠近您的javascript末尾。因为你想“给出正确的答案”,你可能需要稍微改变这些行。然而,你的问题并没有解释我们如何从3中确定哪一个是“正确答案”。也许可以澄清我们如何确定正确答案?这是一家商店,客户将选择任何产品和任何价格,选择数量,并有代码交付总额。这是一个你选择的任何价格的问题,无论产品是什么,只是价格和价值,价格的数量。我所要做的就是把清单上的任何产品的价格乘以数量,再进行小计。非常感谢!!这正是我想要的:D非常感谢!!你帮我省了很多时间!很高兴能帮忙:)
(function($) {
$("document").ready(function() {
$("td").hide();
$("#producto1").change(function() {
$(".e01 td").hide();
$("td." + $(this).val()).show();
});
});
})(jQuery);
var e = document.getElementById("elias");
var strUser = e.options[e.selectedIndex].value;
var e = document.getElementById("elias1");
var strUser1 = e.options[e.selectedIndex].value;
var e = document.getElementById("elias2");
var strUser2 = e.options[e.selectedIndex].value;
$(function () {
$('input').keyup(function (){
var quantity1 = $("#CAT_Custom_500436").val();
var total1 = quantity1 * strUser;
var total1 = quantity1 * strUser1;
var total1 = quantity1 * strUser2;
$("#CAT_Custom_500440").val(total1);
});
});
$(document).ready(function () {
// Cache the variables
var $elias = $('#elias'),
$elias1 = $('#elias1'),
$elias2 = $('#elias2'),
$product = $('#producto1'),
$error = $('.error'),
$container = $('.container');
$("td").hide();
var productValue;
$product.change(function () {
$(".e01 td").hide();
$("td." + $(this).val()).show();
// Only show the container when the selections are not first 2
if (this.value !== 'Selecciona' && this.value !== '00') {
$error.addClass('hide');
$container.removeClass('hide');
} else {
$error.removeClass('hide');
$container.addClass('hide');
}
productValue = this.value;
}).change();
// Bind the change event for Dropdowns
var $quantity = $('#CAT_Custom_500436'),
$total = $("#CAT_Custom_500440");
$elias.add($elias1).add($elias2).change( findTotal);
$quantity.keyup(findTotal);
function findTotal() {
// Get the value
var quan = $quantity.val();
var pri = $('.'+ productValue).find('select').val();
var tot = pri * quan;
$total.val(tot);
}
});