HTML5 type=range - showing label

后端 未结 7 2078
心在旅途
心在旅途 2021-02-12 13:25

Is there a way I can also set some label text for each steps in the HTML5 type=range control. Basically I have a range control

7条回答
  •  南笙
    南笙 (楼主)
    2021-02-12 13:42

    I've put together for you.

    // 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()]);
        });
    
    });
    
    
    

提交回复
热议问题