How to get value from input with dynamically changed value by jquery UI slider?

狂风中的少年 提交于 2019-12-12 05:27:38

问题


I've input text with a dynamically changed value by jquery UI slider. How to get value from $("#scope_input") by jquery? .change event working only from manual keypress on keyboard, on sliding doesn't getting any value:

$("#scope_input").change(function() {
    console.log($(this).val());
});

$("#scope_slider").slider({
    range: "min",
    min: 1,
    max: 100,
    value: 10,
    slide: function(event, ui) {
    $("#scope_input").val(ui.value);
    }
});

回答1:


You need to trigger the change event manually:

$("#scope_input").val(ui.value).change();



回答2:


WHen you update the field within the slide event, trigger the change on the input

$("#scope_slider").slider({
    range: "min",
    min: 1,
    max: 100,
    value: 10,
    slide: function(event, ui) {
    $("#scope_input").val(ui.value).change();
    }
});



回答3:


Did you try

$("#scope_slider").bind("slidechange", function(event, ui) {
    $("#scope_input").val(ui.value);
});


来源:https://stackoverflow.com/questions/12781322/how-to-get-value-from-input-with-dynamically-changed-value-by-jquery-ui-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!