2012-08-09 75 views
3

我是jquery和html5的新手。如何使用jquery在输入类型=范围中更改输入值,最小值和最大值?

我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]); 

    } 

当我选择其值为ON的min和max值滑块分别应该自动成为A1和A50一个单选按钮。当我滑动滑块时,我的值应该从A1变为A50。

我的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> 

您如何看待最小和最大的代码应该是什么?和 如何将输入值从A1更改为A50?

回答

7

输入滑块的值应该只有任何有效的浮点数。所以我不认为它会用你想使用的最小最大值。

至于jQuery的代码来设置最小和最大属性,你应该使用attribute方法:

$('#slider').attr('min', A_Route[0]); 
    $('#slider').attr('max', A_Route[3]); 

看到它的工作here

+0

你答是正确的,但你改变的值。 – Newbie 2012-08-10 18:35:15

相关问题