<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 滑块

      HTML5 Slider with onchange function(具有 onchange 功能的 HTML5 滑块)
          <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 滑块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Rails/Javascript: How to inject rails variables into (very) simple javascript(Rails/Javascript:如何将 rails 变量注入(非常)简单的 javascript)
                quot;Each child in an array should have a unique key propquot; only on first time render of page(“数组中的每个孩子都应该有一个唯一的 key prop仅在第一次呈现页面时)
                CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)
                Ordinals in words javascript(javascript中的序数)
                getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)
                How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社
                <legend id='Mqger'><style id='Mqger'><dir id='Mqger'><q id='Mqger'></q></dir></style></legend>

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

                      • <bdo id='Mqger'></bdo><ul id='Mqger'></ul>
                      • <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>
                      • <small id='Mqger'></small><noframes id='Mqger'>