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 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退