jQuery如果选择的值等于

时间:2012-09-27 08:28:53

标签: jquery select

在我的网站表单中,我需要将var kwh_production乘以与selectbox项目相关联的值。这是我的代码,但不起作用,因为它不检查所选项目,只是将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);

1 个答案:

答案 0 :(得分:0)

select_20应该是你的id或类,而你在比较时缺少==阅读更多解释。

  1. 如果select_20是 ID ,则您的选择器应为$('#select_20'); 如果select_20是,则您的选择器应为$('.select_20');
  2. 比较使用 == 而不是 = if ($('#select_20').val() == 3025)
  3. 希望这会帮助你。如果您有任何疑问,请随时提出。感谢