获取在功能中单击元素的ID [英] Get ID of clicked on element in function
本文介绍了获取在功能中单击元素的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"));
}
这篇关于获取在功能中单击元素的ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文