You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Uncaught ReferenceError错误求助:$(this).val()赋值左侧无效问题

解决"Invalid left-hand side in assignment"错误(jQuery val()方法误用)

Hey there, let's figure out why you're hitting this error and fix it right away.

That "Invalid left-hand side in assignment" message pops up because you're trying to assign a value to the return result of a function—which JavaScript doesn't allow. Let's look at the problematic line specifically:

$(this).val() = parseInt($("#x_gen_income").val());

$(this).val() is a function call that grabs the current value of your element. You can't assign directly to what it returns. Instead, jQuery's val() method is designed to accept a parameter when you want to set an element's value, not just get it.

Here's the fixed version of your code block, with a couple of readability improvements too:

$(this).blur(function(){ 
  // Store parsed values in variables to avoid repeating work
  const currentInputVal = parseInt($(this).val());
  const genIncomeVal = parseInt($("#x_gen_income").val());

  if(currentInputVal > 10000000){ 
    alert("WARNING: INCOME IS ABOVE 10,000,000; PLEASE REVIEW THE INPUT"); 
    // Use val() with a parameter to set the value correctly
    $(this).val(genIncomeVal); 
    $(this).focus(); 
  } else if(currentInputVal === 0){ 
    alert("ERROR: INCOME IS 0, PLEASE REVISE THE INPUT"); 
    $(this).val(''); 
    $(this).focus(); 
  } else if(currentInputVal < 100000){ 
    alert("..."); // Add your remaining alert logic here
  }
});

A couple of quick notes:

  • I added variables for the parsed values to clean up the code and avoid running parseInt() multiple times on the same elements.
  • Fixed a tiny typo in your first alert text ("10,000,00" → "10,000,000") to match the condition you're checking.
  • Switched == to === for strict equality check (a good practice in JavaScript to avoid unexpected type coercion).

内容的提问来源于stack exchange,提问作者Yuuki

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 03:41:46