i have a select tag
<select name="valueAA" id="valueAA">
i use UI Slider, and i need to write a function onchange of select tag, but when it changes via slider, my function doesn't work.
$("#valueAA").change(function()
{
alert("works");// doesn't work
})
can i avoid such behavior without c开发者_Python百科hanging the ui slider
script, and what is the explanation of such behavior?
Thanks
UPDATE
the script looks like this
$(function(){
$('select#valueAA, select#valueBB').selectToUISlider({
labels:6
});
});
where i must put thise script? (i've tried many variant:))
$( ".selector" ).bind( "slidechange", function(event, ui) {
...
});
From what I can see, UI Slider is written on top of jQuery UI's slider. The jQuery UI slider has events that you can tap into, start, slide, change and stop. Using the example from the docs, you could try:
// Bind to the change event by type: slidechange.
$("#valueAA").bind( "slidechange", function(event, ui) {
$(this).change();
});
OR, using your updated example, supply a callback in the options for the slider:
$(function(){
$('select#valueAA, select#valueBB').selectToUISlider({
labels:6,
change: function (event, ui) { $(this).change(); }
});
});
I struggled with this for a while but found the answer to be this:
$('.slider').selectToUISlider({
sliderOptions: {
change:function() {
alert("works");
}
}
});
The select is being changed via the control itself, so the change event isnt being triggered. You should try to bind the change event on the ui slider and use the following code to trigger the change event on the select.
$("#valueAA").trigger("change");
精彩评论