首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JavaScript Calculate Pricing表单在PC上不工作。在Mac上工作。有人能找到错误吗?

JavaScript Calculate Pricing表单在PC上不工作。在Mac上工作。有人能找到错误吗?
EN

Stack Overflow用户
提问于 2010-02-25 10:25:04
回答 1查看 165关注 0票数 1

有人能帮我找出这个问题吗?我永远感谢这个网站一直以来的帮助,并感谢任何建议或想法。谢谢。

实际的页面可以在这里看到:http://www.procollage.com/pricing/photo-collage-pricing.html

代码语言:javascript
复制
 <script LANGUAGE="JavaScript">
function calculate(PricingForm) {
    height = PricingForm.height.value;
    width = PricingForm.width.value;
    photos = PricingForm.photos.value;
    lgtext = PricingForm.lgtext.value;
    mountlam = PricingForm.mount.value;
    mountlam = PricingForm.lam.value;

    price = GetPrice(PricingForm, height, width, photos, lgtext, mount, lam)
    document.PricingForm.collageEstimate.value = "$" + RoundToPennies(price);
}

function GetPrice(PricingForm, height, width, photos, lgtext, mount, lam) {

        price = height * width;
        price = price / 144;
        pricetwo = price; // for lookup later
        price = price * 15;

        price = (PricingForm.lgtext.checked) ? price + 20 : price;
        price = (PricingForm.mount.checked) ? price + pricetwo * 5 : price;
        price = (PricingForm.lam.checked) ? price + pricetwo * 5 : price;

        return (photos * 4.95) + price;
}

function RoundToPennies(n) {
    pennies = n * 100;
    pennies = Math.round(pennies);
    strPennies = "" + pennies;
    len = strPennies.length;
    return strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);
}

</script>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-02-25 10:32:16

您的calculate函数中既没有mount也没有lam变量,我认为这是一个复制/粘贴错误,请看:

代码语言:javascript
复制
function calculate(PricingForm) {
  //...
  mountlam = PricingForm.mount.value; // <--- the same identifier
  mountlam = PricingForm.lam.value;   // <---

  price = GetPrice(PricingForm, height, width, photos, lgtext, mount, lam);
  //..                                                           ^     ^
}

应该是:

代码语言:javascript
复制
//...
mount = PricingForm.mount.value;
lam = PricingForm.lam.value;

price = GetPrice(PricingForm, height, width, photos, lgtext, mount, lam);
//..

还要注意,如果在不使用var语句的情况下进行赋值,这些变量将成为全局变量...

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2331158

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档