获取在功能中单击元素的ID

问题描述:

我想获取我点击的元素的ID。
我将函数放在onclick元素中,如下所示:

I want to get the ID of an element I click on. I put the function in the onclick element, like this:

<a id="myid" class="first active" onclick="markActiveLink();" href="#home">Home</a>

这是在函数中:

function markActiveLink() {   
    alert($(this).attr("id"));
}

这不起作用,因为它没有定义。
它是否真的忘记了ID,我是否必须在onclick中键入它?

This doesn't work, as it says it isn't defined. Does it really forget about the ID, do I have to type it in the onclick?

尝试: onclick =markActiveLink(this);和

function markActiveLink(el) {   
    alert($(el).attr("id"));
}