How to get the form ID attribute in a delegate event
$('form[role=form]').delegate( "input[role=submit_button]", "click", function() {
alert( FORM.ID ); /// ????????????
});
IMPORTANT: without use closest() or parent() ... you know, when you write $('form[role=for开发者_运维知识库m]') here you have the element finded ... why to search it newly ???
this.form.id
should do it ...
explanation
All input elements (input
, select
, button
etc) that are contained in a form
tag, keep a reference to that container in the .form
property.
You cannot do whitout search it again....
alert($(this).closest("form[role=form]").attr("id"));
In that function this
and $(this)
will refer to input[role=submit_button]
if you want a reference to the form you should save it in a variable before calling delegate so:
var myForm = $('form[role=form]');
myForm.delegate( "input[role=submit_button]", "click", function() {
alert( myForm.attr("id") ); /// ????????????
});
精彩评论