1. 程式人生 > >jquery on()事件繫結

jquery on()事件繫結

 $("#test1").on('click', function(e) {
        $(this).text('觸發事件:' + e.type)
    })


$("#test2").on('mousedown mouseup', function(e) {
        $(this).text('觸發事件:' + e.type)
    })


$("#test3").on({
        mousedown: function(e) {
            $(this).text('觸發事件:' + e.type)
        },
        mouseup: function(e) {
            $(this).text('觸發事件:' + e.type)
        }
    })

on()的高階應用

$("div").on("click","p",fn)

   div中的p都綁定了click事件。