jQuery multiple events to trigger the same function

后端 未结 11 1424
青春惊慌失措
青春惊慌失措 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:47

    As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements.

    $(document).on('mouseover mouseout',".brand", function () {
      $(".star").toggleClass("hovered");
    })
    

提交回复
热议问题