0

在我的网站表单中,我需要将var kwh_production连接到选择框项的值相乘。这是我的代码,但不起作用,因为它不检查所选项目,只是乘以kwh_production最后一个值(0.27325)

function earn_or_save() {
    var eos = 0;

    // erd modules
    if ($('select_20').val() = 3025) eos = kwh_production * 0.28525
    if ($('select_20').val() = 4407) eos = kwh_production * 0.28525
    if ($('select_20').val() = 5809) eos = kwh_production * 0.28525
    if ($('select_20').val() = 5850) eos = kwh_production * 0.27325
    if ($('select_20').val() = 8724) eos = kwh_production * 0.27325
    if ($('select_20').val() = 9320) eos = kwh_production * 0.27325
    if ($('select_20').val() = 10464) eos = kwh_production * 0.27325
    if ($('select_20').val() = 13649) eos = kwh_production * 0.27325
    if ($('select_20').val() = 15938) eos = kwh_production * 0.27325    
    if ($('select_20').val() = 16326) eos = kwh_production * 0.27325    
    if ($('select_20').val() = 17612) eos = kwh_production * 0.27325    
    if ($('select_20').val() = 21288) eos = kwh_production * 0.27325    

    // europe modules
    if ($('select_20').val() = 3289) eos = kwh_production * 0.28525
    if ($('select_20').val() = 4882) eos = kwh_production * 0.28525
    if ($('select_20').val() = 6410) eos = kwh_production * 0.28525
    if ($('select_20').val() = 9350) eos = kwh_production * 0.27325
    if ($('select_20').val() = 9350) eos = kwh_production * 0.27325
    if ($('select_20').val() = 10481) eos = kwh_production * 0.27325
    if ($('select_20').val() = 11463) eos = kwh_production * 0.27325
    if ($('select_20').val() = 14745) eos = kwh_production * 0.27325
    if ($('select_20').val() = 17269) eos = kwh_production * 0.27325
    if ($('select_20').val() = 18285) eos = kwh_production * 0.27325
    if ($('select_20').val() = 19772) eos = kwh_production * 0.27325
    if ($('select_20').val() = 23653) eos = kwh_production * 0.27325

    if (eos != 0) {
      $("earn_or_save").set('text', "€ " + number_format(eos, 2, ',', '.'));
      $("i_earn_or_save").value = number_format(eos, 2, '.', '');
    }
    else {
      $("earn_or_save").set('text', "");
      $("i_earn_or_save").value = 0;
    }
  }

$("select_20").addEvent('onChange', earn_or_save);
4

1 回答 1

0

select_20 应该是您的 id 或 class 并且您在比较时缺少 ==。阅读更多解释。

  1. 如果 select_20 是一个id,你的选择器应该是$('#select_20');如果 select_20 是一个,你的选择器应该是$('.select_20')
  2. 比较时使用==而不是= if ($('#select_20').val() == 3025)

希望这会帮助你。如果您有任何问题,请随时提问。谢谢

于 2012-09-27T08:32:04.497 回答