douxianji6181
douxianji6181
2015-02-16 11:19

计算器创建jquery

已采纳

I have created calculator in php. Now i want calculator code in jquery with same functions same formula what are all the php.i need to write jquery calculator.I am new in jquery. i dont know its possible or not.anybody please help me

My php code:

<?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  ?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dongluojiao6322 dongluojiao6322 6年前

    Apart from your specific example using rates: here's a general description that just shows how to make a square-root calculator. You can extend it to meet your needs. In general, you'll need to follow these steps:

    • Include jquery.js in some HTML page that renders your calculator
    • Have <input type="text" id="mynum"/> fields in your HTML where users input values (or use type="number" etc.). Make sure you use id="...." as the field ID, you'll re-use it later.
    • Have a placeholder to show results, e.g. <div id="result">Calculation result will appear here.</div>. Again, id="...." is used to identify this element so that you can put in values using Javascript.
    • Have some buttons to do calculations, e.g. <input type="button" value="SQRT" onclick="sqrt_stuff();"/>

    Next comes the calculation part. The hypothetical above function sqrt_stuff() would then use JQuery to pick up values and paste results; for example:

    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);
    }
    
    点赞 评论 复制链接分享

为你推荐