捐赠日计算器问题

时间:2016-09-18 16:36:04

标签: javascript css html5

嘿,我想知道如何制作这样的计算器 通过输入$ amount,您可以获得多少天的捐赠状态 如图所示 https://www.sixth-sen.se/index.php?/donate/ 我尝试了几种方法和代码,但没有一种方法可以使用

1 个答案:

答案 0 :(得分:0)

不要使用<center>,它是旧的并且已弃用。相反,使用CSS:

&#13;
&#13;
$(document).ready(function() {
  var promotion = 3;

  $("#donations").keyup(function() {
    var amount = $("#donations").val();
    if (amount == "") {
      $("#donation_amout").html("<h3>You have not entered any amount.</h3>");
      document.getElementById('amount').value = amount;
    } else if (amount < 0.50) {
      $("#donation_amout").html("<h3>Not acceptable, must be higher than $0.50!</h3>");
      document.getElementById('amount').value = amount;
    } else if (amount < 1) {
      var count = amount * promotion;
      $("#donation_amout").html("<h3>Contributor Status for <b>0</b> days</h3>");
      document.getElementById('amount').value = amount;
    } else if (amount >= 1 && amount < 100000000) {
      var count = Math.floor(amount) * promotion;
      $("#donation_amout").html("<h3>Contributor Status for <b>" + count + "</b> days</h3>");
      document.getElementById('amount').value = amount;
    } else if (amount > 100000000) {
      $("#donation_amout").html("<h3>The amount is out of range!</h3>");
      document.getElementById('amount').value = amount;
    }
  });
});
&#13;
.amount {
  margin: auto;
  width: 20%;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="amount">
  <h2>Donation Amount</h2>
  <b>$</b> 
  <input type="text" placeholder="Input the donation amount and discover what you'd get" id="donations" name="donation">
  <div id="donation_amout"></div>
</div>
&#13;
&#13;
&#13;