2015-09-04 139 views
0

我正在尝试制作计算器并出现问题。计算没有显示出来。我在想我有什么关系“总计:测试:”不知道这是问题还是代码中的某处。任何人都可以帮助我做我做错了什么。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>

+0

我的回答有效。我也测试过了。如果您发现它有帮助和正确,请将我的答案标记为正确答案。 :) – aimme

回答

0

难道你看到的简单的C,而不是资本的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 
0
$('#total').html(formatCurrency(totalCost)); 
$('#net').html(formatCurrency(nettotalCost)); 

我建议你,而不是使用html的功能.append。