2012-08-09 47 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

相關問題