如何在jquery ui价格范围滑块中动态更改值

时间:2014-02-06 05:52:54

标签: jquery uislider

我使用的是jquery ui价格范围滑块。我可以选择货币。问题是如果用户选择不同的货币,则范围滑块仍然相同。我想在更改货币时更改不同货币的滑块范围值。现在它只显示美元的范围,我想当用户选择欧元时,范围将变为欧元 这就是我正在做的事情

<title>jQuery UI Slider - Range slider</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#slider-range" ).slider({
      range: true,
      min: 0,
      max: 500,
      values: [ 75, 300 ],
      slide: function( event, ui ) {
        $( "#amount" ).val( "$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ] );
      }
    });
    $( "#amount" ).val( "$" + $( "#slider-range" ).slider( "values", 0 ) +
      " - $" + $( "#slider-range" ).slider( "values", 1 ) );
  });
  </script>
</head>
<body>
<select name=currency class=f15>
                    <option value=USD selected>USD</option>
                    <option value=BDT >BDT</option>
                    </select> &nbsp; 
<p>
  <label for="amount">Price range:</label>
  <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;">
</p>

<div id="slider-range"></div>

Fiddle

1 个答案:

答案 0 :(得分:0)

试试这个,

Demo

$(function() {
    $('select').change(function(){
     $( "#amount" ).val( $('select').val() + $( "#slider-range" ).slider( "values", 0 ) +
      " - "+ $('select').val() + $( "#slider-range" ).slider( "values", 1 ) );
    })
    $( "#slider-range" ).slider({
      range: true,
      min: 0,
      max: 500,
      values: [ 75, 300 ],
      slide: function( event, ui ) {
        $( "#amount" ).val( $('select').val() + ui.values[ 0 ] + " - "+ $('select').val() + ui.values[ 1 ] );
      }
    });
    $( "#amount" ).val( $('select').val() + $( "#slider-range" ).slider( "values", 0 ) +
      " - "+ $('select').val() + $( "#slider-range" ).slider( "values", 1 ) );
  });

HTML:

<select name=currency class=f15>
                    <option value="$" selected>USD</option>
                    <option value="&#2547;" >BDT</option>
                    </select> &nbsp; 
<p>
  <label for="amount">Price range:</label>
  <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;">
</p>

<div id="slider-range"></div>