admin管理员组

文章数量:1287230

I have JavaScript method which acts when a particular class (mcb) of forms are submitted:

function BindCloseMessage() {
    $(".mcb").submit(function(event) {
        alert("closing..."); //Here I want to get the id of form
        event.preventDefault();
    });
}

In place of alert call, I need to access the id of form whose submit is called. How can I do it? Even better will be the tip for accessing any attribute...

Thanks

I have JavaScript method which acts when a particular class (mcb) of forms are submitted:

function BindCloseMessage() {
    $(".mcb").submit(function(event) {
        alert("closing..."); //Here I want to get the id of form
        event.preventDefault();
    });
}

In place of alert call, I need to access the id of form whose submit is called. How can I do it? Even better will be the tip for accessing any attribute...

Thanks

Share Improve this question edited Aug 20, 2009 at 11:20 Hemant asked Aug 20, 2009 at 11:14 HemantHemant 19.8k24 gold badges94 silver badges130 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

the id of the form being submitted will be

this.id      

or in jQuery

$(this).attr('id') //although why type the extra letters?
$(".mcb").submit(function(e){
  e.preventDefault();
  $(this).attr("id"); // Returns FORM ID
});

You can learn more about jQuery's attribute-methods at http://docs.jquery./Attributes

本文标签: javascriptHow to access element id and other attributes using jQueryStack Overflow