计算器创建jQuery

纳纳拉苏

我已经在php中创建了计算器。现在我想要具有相同功能相同公式的jquery中的计算器代码,所有php.i都需要编写jquery Calculator。我是jquery中的新手。我不知道它的可能与否。有人请帮助我

我的PHP代码:

<?php

/*
 * Template Name: Calculator-iFrame
 */

get_header();?>

    <!-- Main Content -->
    <div class="large-12 columns" role="content">

        <?php
if (isset($_POST['valuea'])) $valuea = $_POST['valuea'];
if (isset($_POST['valueb'])) $valueb = $_POST['valueb'];
if (isset($_POST['valuec'])) $valuec = $_POST['valuec'];
if (isset($_POST['valued'])) $valued = $_POST['valued'];
if (isset($_POST['valuee'])) $valuee = $_POST['valuee'];
if (isset($_POST['valuef'])) $valuef = $_POST['valuef'];
$answera = (($valueb / $valuea) + ($valued / $valuec) + ($valuef / $valuee)) / 3;


echo <<<_END
<form method='post' action='http://whatsmyrealrate.com/solutionreach'>
<table class="calculator" border='0' width='500px' cellpadding='3' cellspacing='1' class="table">
<tr class="calcheading"><td colspan="3" align="center">Whats your effective rate?</td></tr>
<tr class="monthheading"><td colspan="2"><strong>Month 1</strong></td></tr>
<tr class="calcrow"><td>Total Sales, Including Amex</td><td align="center"><input type='text' name='valuea' value="$valuea"/></td></tr>
<tr class="calcrow2"><td>Total Fees, less any terminal or rental fees</td><td align="center"><input type='text' name='valueb' value="$valueb"/></td></tr>
<tr class="monthheading"><td colspan="2"><strong>Month 2</strong></td></tr>
<tr class="calcrow"><td>Total Sales, Including Amex</td><td align="center"><input type='text' name='valuec' value="$valuec"/></td></tr>
<tr class="calcrow2"><td>Total Fees, less any terminal or rental fees</td><td align="center"><input type='text' name='valued' value="$valued"/></td></tr>
<tr class="monthheading"><td colspan="2"><strong>Month 3</strong></td></tr>
<tr class="calcrow"><td>Total Sales, Including Amex</td><td align="center"><input type='text' name='valuee' value="$valuee"/></td></tr>
<tr class="calcrow2"><td>Total Fees, less any terminal or rental fees</td><td align="center"><input type='text' name='valuef' value="$valuef"/></td></tr>
<tr class="submit"><td colspan="3" align="center"><input type='submit' value='Calculate'/></td></tr>
_END;
?>

<tr class="calcrow">
<td colspan="3" align="center"><?php 

if ($answera > .0238): {
    echo "Your Effective Rate: <br></br>";
    echo  round($answera*100,2);
    } 
elseif ($answer == 0): {
    echo "Your Effective Rate: <br></br>";
    echo  "0.00%";
    } 

else: {
    echo "<strong>Oops, something has gone terribly wrong!</strong> <br></br>
Please attach at least 2 months of your most recent credit card processing statements and one of our specialists will respond within 24 hours with an accurate cost analysis.";
    echo gravity_form( 1, false, false, false, '', false );
}

endif
?>

</td></i>
</tr>
</table>
</form>

    </div>
    <!-- End Main Content -->

<?php  ?>
卡雷尔·库巴特(Karel Kubat)

除了您使用费率的特定示例:这里是一个一般性说明,仅显示了如何制作平方根计算器。您可以扩展它以满足您的需求。通常,您需要执行以下步骤:

  • 在呈现计算器的某些HTML页面中包含jquery.js
  • <input type="text" id="mynum"/>你的HTML领域,用户的输入值(或使用type="number"等)。确保将其id="...."用作字段ID,稍后再使用。
  • 有一个占位符以显示结果,例如<div id="result">Calculation result will appear here.</div>同样,id="...."用于标识此元素,以便您可以使用Javascript输入值。
  • 有一些按钮可以进行计算,例如 <input type="button" value="SQRT" onclick="sqrt_stuff();"/>

接下来是计算部分。假设的上述函数sqrt_stuff()将使用JQuery来拾取值并粘贴结果;例如:

function sqrt_stuff() {
    // Get user input from field with id "mynum"
    var nr = $('#mynum');
    // Calculate root
    var root = Math.sqrt(nr);
    // Show in div with id "result"
    $('#result').html('The answer is: ' + root);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章