Disable track on HTML5 range input

谁说胖子不能爱 提交于 2019-12-30 07:41:42

问题


I'm trying to find a way to prevent the user from clicking into the "track" portion of an HTML5 range input. Essentially, I only want the user to be able to use the "handle" to change the range value.

Is this even possible?


回答1:


It's possible through pointer-events at least on chrome.

input[type=range] {
pointer-events: none;
}

input[type=range]::-webkit-slider-thumb {
pointer-events:auto;
}

This will disable clicking on the track and enable clicking only on slider thumbs.




回答2:


Adding disabled should work.

<input id="rangeindicator" disabled type="range" name="points" min="1" max="10">

and then you can easily change the values using jQuery, like this:

$("#rangeindicator").val(1)


来源:https://stackoverflow.com/questions/24558661/disable-track-on-html5-range-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!