最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get value from jquery slider on every change? - Stack Overflow

programmeradmin5浏览0评论

i have a problem with jquery slider value after changing it. I'm just using normal jquery UI (version 1.10.4) and jquery core 1.7.2

First time after refresh i have a value which i want. But after the change i can't get it. And i need that to have a if statemnet which will change a value of the paragraph.

This is a JQuery code:

$(function() {
  $( "#slider" ).slider({
  range:"min",
  min: 0,
  max: 100,
  value: 10,
  slide: function wynik( event, ui ) {
     $( "#price" ).val("$" + ui.value);
  }
  });
  $( "#price" ).val( "$" + $( "#slider" ).slider( "value") );
    var val = $('#slider').slider("value");
    if ( val >= 20 ) {
       $("#priceText").text("first text");
    } else {
       $("#priceText").text("second text");
    }
});

What is wrong here?

I want to change a text in label:

<p>
<input type="text" id="price">
<label id="priceText" for="price">Some text to change</label>
</p>

Input working correctly and show the value all the time in right way. But label doesn't change (only first time after refresh).

I have read a lot of posts on SO before i post this one. For example: How to get value from jQuery UI slider? or How to get value from input with dynamically changed value by jquery UI slider? But i can't get it done anyway.

i have a problem with jquery slider value after changing it. I'm just using normal jquery UI (version 1.10.4) and jquery core 1.7.2

First time after refresh i have a value which i want. But after the change i can't get it. And i need that to have a if statemnet which will change a value of the paragraph.

This is a JQuery code:

$(function() {
  $( "#slider" ).slider({
  range:"min",
  min: 0,
  max: 100,
  value: 10,
  slide: function wynik( event, ui ) {
     $( "#price" ).val("$" + ui.value);
  }
  });
  $( "#price" ).val( "$" + $( "#slider" ).slider( "value") );
    var val = $('#slider').slider("value");
    if ( val >= 20 ) {
       $("#priceText").text("first text");
    } else {
       $("#priceText").text("second text");
    }
});

What is wrong here?

I want to change a text in label:

<p>
<input type="text" id="price">
<label id="priceText" for="price">Some text to change</label>
</p>

Input working correctly and show the value all the time in right way. But label doesn't change (only first time after refresh).

I have read a lot of posts on SO before i post this one. For example: How to get value from jQuery UI slider? or How to get value from input with dynamically changed value by jquery UI slider? But i can't get it done anyway.

Share Improve this question asked May 2, 2017 at 15:08 27Zaku27Zaku 111 gold badge1 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

You can try this:

$("#selector").change(function() {
    $("#slider-range").slider('values',0,$(this).val());
});

Working Fiddle

Jquery Slider emit a "slidechange" event everytime it change value

Remember, it should be listened on the jQuery element after you've registered the event in the element itself

$( "#slider" ).slider({
    change: function( event, ui ) {
        // register event here
    }
});

$( "#slider" ).on( "slidechange", function( event, ui ) {
    // use ui.value to get the current value
} );

Check the official api wiki for all the slider related events

Official Slider Api

发布评论

评论列表(0)

  1. 暂无评论