dongsu7049 2015-03-24 04:44
浏览 126
已采纳

带有2个滑块的HTML5滑块计算器

I am trying to create an HTML5 slider calculator.

I have created two sliders with different ranges, initial values and step sizes. The two sliders are setup to update the value on the fly as the user moves the slider left and right. The problem is that my first slider updates the second sliders value, but the value of the first slider remains fixed.

The code is as follows:

                                    echo 'Calculate Your Payments:';
                                echo '<div id="rate-block">';
                                echo '<label for="rate_slider">Rate</label>';
                                echo '<input type="range" min="0" max="12" value="5.9" id="rate_slider" step="0.1" oninput="outputUpdate(value)"/>';
                                echo ' <output for="rate_slider" id="rate">5.9</output> APR';
                                echo '<script>';
                                echo 'function outputUpdate(rateVal) {';
                                echo 'document.querySelector(\'#rate\').value = rateVal;';
                                echo '}';
                                echo '</script>';
                                echo '</div>';

                                echo '<div id="term-block">';
                                echo '<label for="term_slider">Term</label>';
                                echo '<input type="range" min="12" max="84" value="60" id="term_slider" step="12" oninput="outputUpdate(value)"/>';
                                echo ' <output for="term_slider" id="term">60</output> Months';
                                echo '<script>';
                                echo 'function outputUpdate(termVal) {';
                                echo 'document.querySelector(\'#term\').value = termVal;';
                                echo '}';
                                echo '</script>';
                                echo '</div>';

This is in PHP.

The live version of the page can be seen at: http://forestlakechev.staging.wpengine.com/inventory/2015/Chevrolet/Cruze/MN/Forest%20Lake/1G1PA5SH0F7130316/?

Next to the vehicle image is some tabbed content. Click on the finance tab and you will see the sliders.

Thank you for your help!

Jared

  • 写回答

1条回答 默认 最新

  • duanli0687 2015-03-24 06:38
    关注

    In JavaScript, when multiple functions have the same name, only the last one to be declared is run. Notice that both JS functions in your code share the same name. Your second outputUpdate() function is overriding the first, so only #term is getting updated. Make sure the functions have different names.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 关于php中URL传递GET全局变量的问题
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件