HTML没有显示结果

时间:2015-09-04 20:49:51

标签: jquery html

我正在尝试制作计算器并遇到问题。计算没有显示出来。我认为我与“总计: 测试:”有关。不确定这是问题还是代码中的某个地方。任何人都可以帮我解决我做错的事。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Calc</title>
  <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
  <script type="text/javascript">
    <!-- 
    $(document).ready(function() {
      $('#calculateTotal').click(function() {

        var inputNum_of_Emp = $('#emp').val();

        var Total_Formula = Math.pow(inputNum_of_Emp, -.2498);

        var totalCost = (9.94 * Total_Formula);

        var nettotalCost = totalcost * inputNum_of_Emp

        $('#total').html(formatCurrency(totalCost));
        $('#net').html(formatCurrency(nettotalCost));
        $('#result').css('display', 'block');
      });
    });
     // This Function I have searched from Web 
    function formatCurrency(strValue) {
      strValue = strValue.toString().replace(/\$|\,/g, '');
      dblValue = parseFloat(strValue);

      blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
      dblValue = Math.floor(dblValue * 100 + 0.50000000001);
      intCents = dblValue % 100;
      strCents = intCents.toString();
      dblValue = Math.floor(dblValue / 100).toString();
      if (intCents < 10)
        strCents = "0" + strCents;
      for (var i = 0; i < Math.floor((dblValue.length - (1 + i)) / 3); i++)
        dblValue = dblValue.substring(0, dblValue.length - (4 * i + 3)) + ',' +
        dblValue.substring(dblValue.length - (4 * i + 3));
      return (((blnSign) ? '' : '-') + '$' + dblValue + '.' + strCents);
    }

    -- >
  </script>
</head>

<body>
  <form id="calc" name="calc">
    <p>
      <label for="emp">Number Of Employees</label>
      <input id="emp" name="empnumber" type="text" />
    </p>
    <p>
      <input name="calculateTotal" id="calculateTotal" type="button" value="Calculate Total" />
    </p>
    <div id="result" style="display:none;"><strong>Total:</strong>  <span id="total"></span><strong>Test:</strong><span id="net"></span>
    </div>
  </form>
</body>

</html>

2 个答案:

答案 0 :(得分:0)

 $('#total').html(formatCurrency(totalCost));
 $('#net').html(formatCurrency(nettotalCost));

我建议您使用.append而不是.html函数。

答案 1 :(得分:0)

你看到简单的c而不是Capital C

var nettotalCost = totalCost * inputNum_of_Emp;

查看您提供的代码。有了这个改变代码工作正常。测试

$('#calculateTotal').click(function() {
      //alert("ok here");

        var inputNum_of_Emp = $('#emp').val();
      //alert(inputNum_of_Emp);
        var Total_Formula = Math.pow(inputNum_of_Emp, -.2498);
      //alert(Total_Formula);
        var totalCost = (9.94 * Total_Formula);
      //alert(totalCost);
        var nettotalCost = totalCost * inputNum_of_Emp;
      //Error: var nettotalCost = totalcost * inputNum_of_Emp  simple c
      //instead of uppercase C in totalCost
      //alert(nettotalCost); //now works fine