HTML5 input type range show range value

后端 未结 12 1330
野趣味
野趣味 2020-11-28 01:51

I am making a website where I want to use range slider(I know it only supports webkit browsers).

I have integrated it fully and works fine. But I would like to use a

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-28 02:17

    Shortest version without form, min or external JavaScript.

    
    0

    Explanation

    If you wanna retrieve the value from the output you commonly use an id that can be linked from the oninput instead of using this.nextElementSibling.value (we take advantage of something that we are already using)

    Compare the example above with this valid but a little more complex and long answer:

    
    0
    

    With the shortest answer:

    • We avoid the use of this, something weird in JS for newcomers
    • We avoid new concept about connecting siblings in the DOM
    • We avoid too much attributes in the input placing the id in the output

    Notes

    • In both examples we don't need to add the min value when equal to 0
    • Removing JavaScript’s this keyword makes it a better language

提交回复
热议问题