0

I have a simple slider UI and I want to get the value as it changes dynamically, but I can't seem to make it work. I have:

<script type="text/javascript">
    $(function() {
        $( "#slider" ).slider({
            value:0,
            min: 0,
            max: 24,
            step: 1,
            slide: function( event, ui ) {
              $( "#amount" ).val( ui.value + " hrs");
            }
        });
        $( "#amount" ).val( $( "#slider" ).slider( "value" ) + " hrs" );
    });
  });
</script>

and...

<p>
<label for="amount">Time (1hr increments):</label>
<input type="text" id="amount" />
</p>
    <div id="slider"></div>

And to check I have it working I am using:

$("#slider").change(function() {
   alert($("#slider").val());
});

But no joy. Sorry if I am being overly dumb! Any help would be much appreciated.

4

2 に答える 2

1

Try this instead change() method:

$("#slider").bind("slidechange", function(event, ui) {
    alert(ui.value);
});
于 2012-10-02T20:56:00.027 に答える
1

Have you tried with the jQuery 'on' method?

$('#slider').on('change', function() {
   alert($('#slider').val());
});
于 2012-10-02T21:07:30.123 に答える