HTML5 type=range - showing label

2020-06-07 07:35发布

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 <input type="range" step=1 min=0 max=4> and for each steps I want some label to be shown in the control. Is there a way to do this?

标签: html
7条回答
Root(大扎)
2楼-- · 2020-06-07 08:08

I guess the easiest solution (plain Javascript) is:

<fieldset>
    <label for="rangeVal">resolution (dpi):</label>
    <input type ="range" max="1000" min="20"
        oninput="document.getElementById('rangeValLabel').innerHTML = this.value;"
        step="1" name="rangeVal" id="rangeVal" value="200">
    </input>
    <em id="rangeValLabel" style="font-style: normal;"></em>
</fieldset>

This code does not need jQuery nor CSS and should work on any browser that supports the range input type.

查看更多
登录 后发表回答