jQuery 只读滑块 - 怎么办?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/970358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery readonly slider - how to do?
提问by inkedmn
How can I have a jQuery slider that is readonly? One that would display a value but the user wouldn't be allowed to move it?
我怎样才能拥有一个只读的 jQuery 滑块?一个会显示一个值但不允许用户移动它的?
Thanks
谢谢
回答by inkedmn
The documentation says there's a .slider('disable')
function - not sure what that actually does to the slider element itself, but that may be an option for you.
文档说有一个.slider('disable')
功能 - 不确定它实际上对滑块元素本身做了什么,但这可能是你的一个选择。
回答by JJ_Coder4Hire
I tried all suggested. Only this works:
我尝试了所有建议。只有这样有效:
$('#mySlider').slider({ disabled: true });
回答by Konstantin Fadeyev
Disabling it makes it transparent. If you want it to look like a normal slider, you can override slide handler to return false:
禁用它使其透明。如果你想让它看起来像一个普通的滑块,你可以覆盖幻灯片处理程序以返回 false:
$("#mySlider").on("slide", function (event, ui) { return false; });
回答by miti737
I have got the same issue that the slider disappears if I use directly $('#mySlider').slider( 'disable' );. I have loaded the slider fisrt..then disabled it. Though it is not a good way, but it works for me.
如果我直接使用 $('#mySlider').slider('disable');,我遇到了同样的问题,即滑块消失。我已经加载了滑块 fisrt..然后禁用它。虽然这不是一个好方法,但它对我有用。
$('#mySlider').slider(
{
range: "min",
min: 0,
max: 100,
value: $("span", this).text(),
}
});
$('#mySlider').slider( 'disable');
回答by karim79
You would simply have to do this:
你只需要这样做:
$('#mySlider').slider( 'disable' );
回答by Mark Vital
$("#slider").slider("disable")
works fine, however reenabling doesn't work $("#slider").slider("enable")
$("#slider").slider("disable")
工作正常,但重新启用不起作用 $("#slider").slider("enable")
回答by Ken
I had a client request for this today. Its probably a good idea to do this as a best practice and prevent string input.
我今天有一个客户要求。将其作为最佳实践并防止字符串输入可能是一个好主意。
Since the slider sets the value in an <input> tag, you can make it "readonly".
由于滑块在 <input> 标记中设置值,因此您可以将其设置为“只读”。
<p>
<label for="amount">Price range:</label>
<input type="text" id="amount" style="border: 0; color: #f6931f; font-weight: bold;" readonly />
</p>
<div id="slider-range"></div>