How to get value from input with dynamically chang

2019-09-02 08:57发布

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);
    }
});

3条回答
倾城 Initia
2楼-- · 2019-09-02 09:38

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楼-- · 2019-09-02 09:43

You need to trigger the change event manually:

$("#scope_input").val(ui.value).change();
查看更多
仙女界的扛把子
4楼-- · 2019-09-02 09:58

Did you try

$("#scope_slider").bind("slidechange", function(event, ui) {
    $("#scope_input").val(ui.value);
});
查看更多
登录 后发表回答