HTML5 type = range – 显示标签

前端之家收集整理的这篇文章主要介绍了HTML5 type = range – 显示标签前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法我也可以为 HTML5类型=范围控件中的每个步骤设置一些标签文本.基本上我有一个范围控制< input type =“range”step = 1 min = 0 max = 4>对于每个步骤,我希望在控件中显示一些标签.有没有办法做到这一点?

解决方法

我已经为你安排了
// define a lookup for what text should be displayed for each value in your range
var rangeValues =
{
    "1": "You've selected option 1!","2": "...and now option 2!","3": "...stackoverflow rocks for 3!","4": "...and a custom label 4!"
};


$(function () {

    // on page load,set the text of the label based the value of the range
    $('#rangeText').text(rangeValues[$('#rangeInput').val()]);

    // setup an event handler to set the text when the range value is dragged (see event for input) or changed (see event for change)
    $('#rangeInput').on('input change',function () {
        $('#rangeText').text(rangeValues[$(this).val()]);
    });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="range" id="rangeInput" name="rangeInput" step="1" min="0" max="4">
<label id="rangeText" />

猜你在找的HTML5相关文章