【问题标题】:get input value and change div [duplicate]获取输入值并更改 div [重复]
【发布时间】:2018-02-25 17:49:48
【问题描述】:

我正在尝试使用输入值更改跨度,我的代码有什么错误。

$(document).ready(function(){
  if ($('#tnx-status').val() = 'publish'){
    $("#status-p").html("Complited")
  }
  	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="tnxst" type="hidden" id="tnx-status" value="publish" />
<span id="status-p"></span>

【问题讨论】:

  • 查看浏览器的调试控制台。它准确地告诉你问题是什么。甚至只需在您自己的问题中单击“运行代码 sn-p”。
  • 我正在尝试,但无法解决此问题
  • 当您尝试时,错误信息是什么?它指的是哪一行代码?错误消息告诉您什么以及您如何尝试将该信息应用于您的代码?
  • "ReferenceError: invalid assignment left-hand side", "lineno": 16, "colno": 7 但作为 jquery 的新手,我无法理解。
  • 问题是您的代码中有错字。您使用的是= 而不是==(或===)。

标签: javascript jquery


【解决方案1】:

使用比较运算符===,而不是赋值运算符=

$(document).ready(function(){
  if ($('#tnx-status').val() === 'publish'){
    $("#status-p").html("Complited")
  }
  	});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="tnxst" type="hidden" id="tnx-status" value="publish" />
<span id="status-p"></span>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-06
    • 2018-03-12
    • 2023-04-05
    • 1970-01-01
    • 2017-03-27
    相关资源
    最近更新 更多