jQuery multiple events to trigger the same function

后端 未结 11 1072
青春惊慌失措
青春惊慌失措 2020-11-22 04:45

Is there a way to have keyup, keypress, blur, and change events call the same function in one line or do I have to do the

11条回答
  •  粉色の甜心
    2020-11-22 05:30

    This is how i do it.

    $("input[name='title']").on({
        "change keyup": function(e) {
            var slug = $(this).val().split(" ").join("-").toLowerCase();
            $("input[name='slug']").val(slug);
        },
    });
    

提交回复
热议问题