gpt4 book ai didi

javascript - 用于 Wordpress 的 PHP 计算器无法正常运行

转载 作者:行者123 更新时间:2023-11-28 09:13:54 25 4
gpt4 key购买 nike

一直在努力让我的计算器工作。我使用 PHP、JS 和 CSS 对计算器进行了编码。非常基本,但是当按下计算按钮时,计算没有完成。这是我的代码。

<?php
/*
Template Name: Calculator
*/

wp_enqueue_script('calc_js', get_bloginfo('template_url').'/library/calc.js');
wp_enqueue_style('calc_css', get_bloginfo('template_url').'/library/calc.css');
get_header(); ?>

<?php
while ( have_posts() ) : the_post();
?>
<div id="page-content-container">

<article <?php post_class('clearfix') ?> id="post-<?php the_ID(); ?>">

<div class="entry-content">
<?php the_content(); ?>

<div class="row-fluid" id="">
<div class="calc span6">
<h3>Payment Calculator</h3>
<p>Our monthly payment calculator will help you work out how much your purchase may cost with various loan amounts. Enter your figures into the top section, then click 'Calculate'. If you want to try different figures you can 'Clear' the form.</p>
<form action="#" method="post">
<p>
<label>Purchase price*</label>
<span class="field">£ <input class="purchase"/></span>
</p>
<p>
<label>Loan amount*</label>
<span class="field">£ <input class="loan"/></span>
</p>
<p>
<label>LTV (Loan To Value)</label>
<span class="field"><input class="blank ltv"/> %</span>
</p>
<p>
<label>Interest Only*</label>
<span class="field">£ <input onfocus="this.blur()" class="blank interest"/></span>
</p>
<input class="reset" type="reset" value="Clear"/><input class="calculate" type="button" value="Calculate"/>
</form>
<p><em>* Need to also consider cost of repayment method to repay your loan. This information is for illustrative purposes only and does not contain all of the details you need to choose a loan.</em></p>
</div><!-- /.calc -->

<div class="calc2 span6">
<h3>Yield Calculator</h3>
<p>The yield calculator will help you measure the return of an investment property by comparing rental income and property value. The yield is the amount of rent generated each year expressed as a percentage of the property value or purchase price.</p>
<form action="#" method="post">
<p>
<label>Monthly Rent</label>
<span class="field">£ <input class="rent"/></span>
</p>
<p>
<label>Property Value</label>
<span class="field">£ <input class="loan"/></span>
</p>
<p>
<label>Yield</label>
<span class="field"><input onfocus="this.blur()" class="yield blank"/> %</span>
</p>
<input class="reset" type="reset" value="Clear"/><input class="calculate" type="button" value="Calculate"/>
</form>
<p><em>* This calculator is based on the gross yield. It is based on the property being tenanted and receiving rent for 12 months of the year. This information is for illustration purposes only and doesn’t take into account any other costs associated with the property.</em></p>
</div><!-- /.calc2 -->
</div><!-- /.row-fluid-->
</div><!-- .entry-content -->

</article>

</div>
<?php
endwhile;
?>

<?php get_footer(); ?>

这是我的 JS 代码:

jQuery(document).ready(function() {

jQuery('.calc .calculate').click(function() {
var parent = jQuery(this).parents('.calc');
parent.find('.error').removeClass('error');

var error = false;

var purchase = parent.find('.purchase');
var loan = parent.find('.loan');

var purchaseval = purchase.val();
if (isNaN(purchaseval) || purchaseval == '') {
error = true;
purchase.addClass('error');
}
var loanval = loan.val();
if (isNaN(loanval) || loanval == '') {
error = true;
loan.addClass('error');
}

if (error == false) {
var perc = (loanval / purchaseval) * 100;
parent.find('.ltv').val(perc.toPrecision(2));

var val = loanval - (loanval * .0125);
var val2 = loanval - val;
parent.find('.interest').val(val2);
}

return false;
});

jQuery('.calc2 .calculate').click(function() {
var parent = jQuery(this).parents('.calc2');
parent.find('.error').removeClass('error');
var error = false;

var rent = parent.find('.rent');
var value = parent.find('.loan');

var rentval = rent.val();
if (isNaN(rentval) || rentval == '') {
error = true;
rent.addClass('error');
}
var valueval = value.val();
if (isNaN(valueval) || valueval == '') {
error = true;
value.addClass('error');
}

if (error == false) {
var yieldval = (rentval * 12) / valueval;


parent.find('.yield').val(yieldval * 100);
}

return false;
});
})

最佳答案

您的 js 似乎对我来说工作正常。看这个Fiddle

关于javascript - 用于 Wordpress 的 PHP 计算器无法正常运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26380676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com