douhuiwan5141 2014-11-28 17:40
浏览 119

AJAX,JQuery,点击按钮后计算价格

I want to calculate the price after a button click. I have 3 buttons which are selectable. For example : button1 = 50$, button2 = 100$, button3 = 200$ Now I want to update the price after a button click. Is there any solution to handle this? Because, If i send the Ajax request and update my html-element the price isn't added. My old price always disappear. So if the user selects button1 the price is 50$, but if the user also selects button2 my price is 100$, not $150.

Thanks :)

  • 写回答

1条回答 默认 最新

  • douji9734 2014-11-28 17:54
    关注

    Here is the idea:

    <script>
        function add(x) {
            document.getElementById('result').innerText =  +(document.getElementById('result').innerText) + x;
        }
    </script>
    <form>
        <input type="button" onclick="add(50)" value="50">
        <input type="button" onclick="add(100)" value="100">
        <input type="button" onclick="add(200)" value="200">
    </form>
    <div id='result'></div>
    

    Note: +(x) forces conversion of x to number

    评论

报告相同问题?

悬赏问题

  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,