jQuery 如何使用jquery更改输入类型=范围中的输入值、最小值和最大值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11893350/
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
How to change the input values, min value and max value in the input type=range using jquery?
提问by Newbie
I'm new to jquery and html5.
我是 jquery 和 html5 的新手。
My jquery is:
我的jQuery是:
var A_Route=['A1','A2','A3',.....'A50'];
var counter=0;
$("input[name='radio-choice']").change(function(){
if ($(this).val() == "on")
{
$('#slider').val(A_Route[counter]);
}
When I select a radio button whose value is ON the min and max value for the slider should automatically become A1 and A50 respectively. And as I slide through the slider my values should change from A1 to A50.
当我选择一个值为 ON 的单选按钮时,滑块的最小值和最大值应分别自动变为 A1 和 A50。当我滑过滑块时,我的值应该从 A1 更改为 A50。
My Html Is:
我的 HTML 是:
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<legend>Layout view:</legend>
<input type="radio" name="radio-choice" id="radio-choice-c" value="on" checked="checked" />
<label for="radio-choice-c">List</label>
<input type="radio" name="radio-choice" id="radio-choice-d" value="off" />
<label for="radio-choice-d">Grid</label>
<input type="radio" name="radio-choice" id="radio-choice-e" value="other" />
<label for="radio-choice-e">Gallery</label>
</fieldset>
</div>
<div data-role="fieldcontain">
<label for="slider">Room:</label>
<input type="range" name="slider" id="slider" value="--------" min=? max=? data-highlight="true" />
</div>
What do you think the min and max code should be? and How can I change the input values from A1 to A50?
你认为最小和最大代码应该是什么?以及如何将输入值从 A1 更改为 A50?
回答by effectica
The value of the input slider should only be any valid floating point number. So I don't think it is going to work with the min max values you want to use.
输入滑块的值只能是任何有效的浮点数。所以我认为它不适用于您要使用的最小最大值。
With regards to the jQuery code to set min and max attributes, you should use the attributemethod:
关于设置 min 和 max 属性的 jQuery 代码,您应该使用属性方法:
$('#slider').attr('min', A_Route[0]);
$('#slider').attr('max', A_Route[3]);
See it working here
看到它在这里工作