<bdo id='KEaNv'></bdo><ul id='KEaNv'></ul>

    <small id='KEaNv'></small><noframes id='KEaNv'>

    1. <i id='KEaNv'><tr id='KEaNv'><dt id='KEaNv'><q id='KEaNv'><span id='KEaNv'><b id='KEaNv'><form id='KEaNv'><ins id='KEaNv'></ins><ul id='KEaNv'></ul><sub id='KEaNv'></sub></form><legend id='KEaNv'></legend><bdo id='KEaNv'><pre id='KEaNv'><center id='KEaNv'></center></pre></bdo></b><th id='KEaNv'></th></span></q></dt></tr></i><div id='KEaNv'><tfoot id='KEaNv'></tfoot><dl id='KEaNv'><fieldset id='KEaNv'></fieldset></dl></div>
    2. <legend id='KEaNv'><style id='KEaNv'><dir id='KEaNv'><q id='KEaNv'></q></dir></style></legend>
    3. <tfoot id='KEaNv'></tfoot>

      具有 onchange 功能的 HTML5 滑块

      时间:2024-04-18
          <bdo id='Imu3g'></bdo><ul id='Imu3g'></ul>
          <legend id='Imu3g'><style id='Imu3g'><dir id='Imu3g'><q id='Imu3g'></q></dir></style></legend>
          1. <small id='Imu3g'></small><noframes id='Imu3g'>

            • <tfoot id='Imu3g'></tfoot>

                  <tbody id='Imu3g'></tbody>
              1. <i id='Imu3g'><tr id='Imu3g'><dt id='Imu3g'><q id='Imu3g'><span id='Imu3g'><b id='Imu3g'><form id='Imu3g'><ins id='Imu3g'></ins><ul id='Imu3g'></ul><sub id='Imu3g'></sub></form><legend id='Imu3g'></legend><bdo id='Imu3g'><pre id='Imu3g'><center id='Imu3g'></center></pre></bdo></b><th id='Imu3g'></th></span></q></dt></tr></i><div id='Imu3g'><tfoot id='Imu3g'></tfoot><dl id='Imu3g'><fieldset id='Imu3g'></fieldset></dl></div>
                本文介绍了具有 onchange 功能的 HTML5 滑块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个滑块(输入类型范围),它应该在更改值时运行一个函数.然后该函数应在单独的 div 容器中显示新值.在函数中放置警报后,我知道该函数没有被调用,但是在谷歌搜索了一个小时并尝试了几种不同的方法后,我找不到错误.

                I have a slider (input type range) that is supposed to run a function when the value is being changed. The function should then display the new value in a separate div container. After placing an alert in the function, I know that the function isn't being called, but after googling for an hour and trying a few different methods I just can't find the error.

                这是 HTML 部分:

                Here's the HTML part:

                <input id="slide" type="range" min="1" max="100" step="1" value="10" onchange="updateSlider(this.value)">
                
                <div id="sliderAmount"></div>
                

                JavaScript:

                JavaScript:

                // Slider
                function updateSlider(slideAmount)
                {
                  alert("error");
                  var sliderDiv = document.getElementById("sliderAmount");
                  sliderDiv.innerHTML = slideAmount;
                }
                

                推荐答案

                可以,你只需要确保在渲染元素时定义了JavaScript函数,例如:

                It works, you just need to make sure that the JavaScript function is defined when the element is rendered, for example:

                <script>
                    function updateSlider(slideAmount) {
                        var sliderDiv = document.getElementById("sliderAmount");
                        sliderDiv.innerHTML = slideAmount;
                    }
                </script>
                <input id="slide" type="range" min="1" max="100" step="1" value="10" onchange="updateSlider(this.value)">
                <div id="sliderAmount"></div>
                

                查看此演示:https://jsfiddle.net/Mmgxg/

                更好的方法是删除内联 onchange 属性:

                A better way would be to remove the inline onchange attribute:

                <input id="slide" type="range" min="1" max="100" step="1" value="10">
                <div id="sliderAmount"></div>
                

                然后在你的 JavaScript 代码中添加监听器:

                And then add the listener in your JavaScript code:

                var slide = document.getElementById('slide'),
                    sliderDiv = document.getElementById("sliderAmount");
                
                slide.onchange = function() {
                    sliderDiv.innerHTML = this.value;
                }
                

                https://jsfiddle.net/PPBUJ/

                这篇关于具有 onchange 功能的 HTML5 滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:带有中间点标记的范围输入(滑块) 下一篇:您如何允许用户手动调整 &lt;div&gt;垂直元素?

                相关文章

                <legend id='Mqger'><style id='Mqger'><dir id='Mqger'><q id='Mqger'></q></dir></style></legend>

                <tfoot id='Mqger'></tfoot>

                  • <bdo id='Mqger'></bdo><ul id='Mqger'></ul>
                1. <i id='Mqger'><tr id='Mqger'><dt id='Mqger'><q id='Mqger'><span id='Mqger'><b id='Mqger'><form id='Mqger'><ins id='Mqger'></ins><ul id='Mqger'></ul><sub id='Mqger'></sub></form><legend id='Mqger'></legend><bdo id='Mqger'><pre id='Mqger'><center id='Mqger'></center></pre></bdo></b><th id='Mqger'></th></span></q></dt></tr></i><div id='Mqger'><tfoot id='Mqger'></tfoot><dl id='Mqger'><fieldset id='Mqger'></fieldset></dl></div>
                2. <small id='Mqger'></small><noframes id='Mqger'>