jQuery: Find clicked element when binding to a form submission event?

前端 未结 2 1409
别那么骄傲
别那么骄傲 2021-01-01 21:59

I think this should be simple. Say I\'ve got the following jQuery:

$someForm.live(\'submit\', function(event) {
// do something
});

If there

2条回答
  •  甜味超标
    2021-01-01 22:44

    Normally you can use event.target for the element itself...and in this case, since it's a native DOM property, just use .name as well:

    $someForm.live('submit', function(event) {
      var name = event.target.name;
    });
    

    However, since submit doesn't originate from the button, only a click does, you want something more like this:

    $("form :submit").live('click', function(event) {
      var name = this.name;
    });
    

    Use this here, because as @patrick points out, a

提交回复
热议问题