Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 计算百分比_Javascript_Jquery_Asp Classic - Fatal编程技术网

Javascript 计算百分比

Javascript 计算百分比,javascript,jquery,asp-classic,Javascript,Jquery,Asp Classic,我正在寻找建立一个网页,提交到数据库(.asp),但也计算一个百分比 百分比金额为8% 理想情况下,我希望用户在输入框中键入金额(例如,假设为100英镑) 然后在下面是另一个输入框,自动计算100英镑+8%(即108英镑) 我不知道如何开始,所以我没有任何代码 $('#output').text = (int)($('#input').text.Substring(0, $('#input').text.Length - 1)) * 1,08 + $('#input').text.Substri

我正在寻找建立一个网页,提交到数据库(.asp),但也计算一个百分比

百分比金额为8%

理想情况下,我希望用户在输入框中键入金额(例如,假设为100英镑)

然后在下面是另一个输入框,自动计算100英镑+8%(即108英镑)

我不知道如何开始,所以我没有任何代码

$('#output').text = (int)($('#input').text.Substring(0, $('#input').text.Length - 1)) * 1,08 + $('#input').text.Substring($('#input').text.Length - 1);
这是您的jQuery:

$("#val").on('keyup', function(){
    $("#incPerc").text(parseInt($(this).val())*1.08);
});
您可能希望使用库将输入限制为仅数字。 大概是这样的:

添加了第二个输入 和两位数的整数:

$("#val").on('keyup', function(){
    var withPerc = parseFloat($(this).val())*1.08;
    $("#incPerc").text(withPerc.toFixed(2));
    $("#otherInput").val(withPerc.toFixed(2));
});
编辑:确定,注释的完整代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script src="http://code.jquery.com/jquery-2.0.0.js" type="text/javascript"></script>
  </head>
  <body>
    <form>
      <input id="val">
      <input id="otherInput">
    </form>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#val").on('keyup', function(){ 
                var withPerc = parseFloat($(this).val())*0.08; 
                $("#incPerc").text(withPerc.toFixed(2)); 
                $("#otherInput").val(withPerc.toFixed(2)); 
            });
        });
    </script>
  </body>
</html>

无标题文件
$(文档).ready(函数(){
$(“#val”).on('keyup',function(){
var withPerc=parseFloat($(this).val())*0.08;
$(“#incPerc”).text(withPerc.toFixed(2));
$(“#其他输入”).val(带perc.toFixed(2));
});
});

链接jQuery库时忘记了协议。(和doc.ready)

您可以开始使用JavaScriptThank JP,如果可能,我需要另一个输入框中的计算?我需要把这两个数字都输入数据库当然,没问题<代码>$(“#idOtherTextBox”).val(parseInt($(this.val())*1.08)