function(e){e.something…} What is e?

后端 未结 5 476
青春惊慌失措
青春惊慌失措 2021-01-06 04:22

When I write

$(\"#new_lang\").click(function(e) 
{
  alert(\"something\");
  e.stopPropagation();
});

What is e here, and

5条回答
  •  生来不讨喜
    2021-01-06 05:01

    e, in this context, is the event object raised by the click event. It will work perfectly well without it (albeit, in your example you will be unable to stopPropagation):

    $("#new_lang").click(function() 
    {
      alert("something");
    });
    

    You can also substitute any name for e, as you would with any function param

    $("#new_lang").click(function(eventObj) 
    {
      alert("something");
      eventObj.stopPropagation();
    });
    

提交回复
热议问题