首页javascriptonjQuery Method - 如何使用on()为新的未来添加的元素添加事件处理程序

jQuery Method - 如何使用on()为新的未来添加的元素添加事件处理程序

我们想知道如何使用on()为新的未来添加的元素添加事件处理程序。

<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){
    $('div').append('<input type="button" class="hulk" value="click me"/>');
    $('.hulk').on('click', function(){
        console.log('me');
    });
});
</script>
</head>
<body>
  <div></div>
</body>
</html>