Jquery 使用SelectToIsLider更改事件
我指的是 以及难以在滑块上检索所选值。 最初我有一个下拉列表,其中有一个与之关联的onchange事件。。 他打电话来很有魅力Jquery 使用SelectToIsLider更改事件,jquery,onchange,uislider,Jquery,Onchange,Uislider,我指的是 以及难以在滑块上检索所选值。 最初我有一个下拉列表,其中有一个与之关联的onchange事件。。 他打电话来很有魅力 <select id="myselect" onchange="myfunction(this);" > 它让我想起了这个。val()不是一个函数 我也试着用 $('select#myselect').selectToUISlider({sliderOptions: {stop: function(e,ui) {alert(ui);}}}); 但使用
<select id="myselect" onchange="myfunction(this);" >
它让我想起了这个。val()不是一个函数
我也试着用
$('select#myselect').selectToUISlider({sliderOptions: {stop: function(e,ui) {alert(ui);}}});
但使用ui参数也无法检索所选值。。。它只返回所选的索引
下拉列表看起来像这样
<select name="myselect" id="myselect">
<option value="20">txt1</option>
<option value="30">txt2</option>
<option value="40" selected="selected">txt3</option>
<option value="50">txt4</option>
<option value="60">txt5</option>
</select>
txt1
txt2
txt3
txt4
txt5
如果我能够触发选择框的onchange事件,那就太好了,但是使用滑块时,下拉列表的值会改变,但不会触发事件
非常感谢您的帮助
谢谢您正在使用的事件是UI滑块,而不是
…但是
值已经更新,所以只需获取它,如下所示:
$('#myselect').selectToUISlider({
sliderOptions: {
stop: function(e,ui) {
var currentValue = $('#myselect').val();
}
}
});
$("select").selectToUISlider({
// labels and tooltipSrc are selectToUISlider specific options
labels: 0,
tooltipSrc: "value",
sliderOptions: {
// swapped out stop for change here
change: function(e,ui) {
console.log($('select').val());
}
}
});
我只是偶然发现了同样的问题,如果滑块或选择下拉菜单发生更改,我需要获取新值,但是当我使用选择下拉菜单时,“停止”选项不起作用。所以我只是用了一个函数的slideoptions“change”选项。就像Nick的回答一样,但是像这样:
$('#myselect').selectToUISlider({
sliderOptions: {
stop: function(e,ui) {
var currentValue = $('#myselect').val();
}
}
});
$("select").selectToUISlider({
// labels and tooltipSrc are selectToUISlider specific options
labels: 0,
tooltipSrc: "value",
sliderOptions: {
// swapped out stop for change here
change: function(e,ui) {
console.log($('select').val());
}
}
});
这就是我最终做的,因为下拉列表正在改变。。。我调用下拉列表并读取其值$('select#myselect').selectToUISlider({slideoptions:{stop:myFunction($(this.parent().find('select')[0])});在myFunction中,我读取下拉列表中选择的内容。。。有人有更好的主意吗?