2011-06-16 67 views
0

我有一个简单的jQuery滑块,我想通过在输入字段中输入数量来更新max:value。这是我到目前为止:从输入字段更新jQuery滑块的最大值

<input name="cost" type="text" class="inputbox" size="10" id="cost" /> 

<label for="status">Progress Bar:</label> 
    <input type="text" id="status" style="border:0; color:#158FB6;font-weight:bold; background-color:#F8F8F8" name="status"/> 
    <div id="status-range" style="width: 250px;margin-top:2px"></div> 

$(function() { 
    $("#status-range").slider({ 
     value:0, 
     min: 0, 
     max: 0, 
     slide: function(event, ui) { 
      $("#status").val("$" + ui.value); 
     } 
    }); 
    $("#status").val("$" + $("#status-range").slider("value")); 
}); 

现在,当用户在成本字段中输入值我想max:0自动更新。

回答

1

添加此事件侦听器:

$('#cost').change(function() { 
    $('#status-range').slider('option','max',$(this).val()); 
}); 
+0

谢谢你,但你的解决方案不起作用。我希望能够通过输入成本字段来控制最大值 – Alex 2011-06-16 17:20:41

+0

更新了代码。对不起,错字。 – js1568 2011-06-16 17:34:23

+0

非常感谢。完美的作品。 – Alex 2011-06-16 17:58:04