首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >javascript语句返回值

问javascript语句返回值
EN

Stack Overflow用户
提问于 2018-12-06 15:40:18
回答 2查看 2.6K关注 0票数 1

我试图从一个名为ValuationChoice (标记为Job )的html输入框中获取一个数字值,并将其传递给Javascript函数(GetPermit_Price),在该函数中,它将循环遍历嵌入到ValuationChoice中的值,从而获得许可成本。无论我在ValuationChoice输入框中输入了什么,结果值总是以0的形式出现。如能就我如何完成这项工作提出任何建议,将不胜感激。提前谢谢!

​

代码语言:javascript
复制
function GetPermit_Price() {

  var PermitCost = 0;
  var theForm = document.forms["cakeform"];
  var Valuation =
    theForm.elements["ValuationChoice"];

  if (Valuation > 0 && Valuation <= 1000) {
    PermitCost = 0;
  }

  if (Valuation > 1001 && Valuation <= 50000) {
    PermitCost = (((Valuation - 1000) / 1000) * 5.50) + 25;
  }

  if (Valuation > 50001 && Valuation <= 100000) {
    PermitCost = (((Valuation - 50000) / 1000) * 4.50) + 294.50;
  }

  if (Valuation > 100001 && Valuation < 500000) {
    PermitCost = (((Valuation - 100000) / 1000) * 3.50) + 519.50;
  }

  if (Valuation > 500001) {
    PermitCost = (((Valuation - 500000) / 1000) * 2.25) + 1919.50;
  }

  return PermitCost;
}

function calculateTotal() {

  var cakePrice = GetPermit_Price() + 5 + 10.00;

  var divobj7 = document.getElementById('permitFee');
  divobj7.style.display = 'block';
  divobj7.innerHTML = "Permit Fee: $" +
    GetPermit_Price();
}

function hideTotal() {
  var divobj = document.getElementById('totalPrice');
  divobj.style.display = 'none';
}
代码语言:javascript
复制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 
    Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1- 
    strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>Cake Form</title>
  <script type="text/javascript" src="js/formcalculations.js"></script>
  <link href="styles/cakeform.css" rel="stylesheet" type="text/css" />

</head>

<body onload='hideTotal()'>
  <div id="wrap">
    <form action="" id="cakeform" onsubmit="return 
    false;">
      <div>
        <div class="cont_order">
          <fieldset>
            <legend>Calculate Permit</legend>

            <label>Job Value</label>
            <input type="text" id="ValuationChoice" name='ValuationChoice' />

            <p>
            </p>
            <div id="permitFee"></div>
            <br/>

            <br/>
            <div id="totalPrice"></div>

            <input type='submit' id='submit' value='Calculate Permit' onclick="calculateTotal()" />

          </fieldset>
        </div>

      </div>
    </form>
  </div>
  <!--End of wrap-->

</body>

</html>

​

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-12-06 15:44:21

估价是输入字段,而不是其价值。

尝试:

代码语言:javascript
复制
var Valuation = theForm.elements["ValuationChoice"].value;
票数 8
EN

Stack Overflow用户

发布于 2018-12-06 15:47:41

所以,首先输入应该是type=number,为什么不像下面这样找到输入的值

代码语言:javascript
复制
const Valuation = document.getElementById('ValuationChoice').value;

当然,只需记录一下您得到的信息。

代码语言:javascript
复制
console.log(Valuation);

这将帮助您调试,并查看您是否得到一个数字,如果您使用文本输入,您可能不会。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53654855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档