开发者

How do you pass the target element as an argument to an inline event handler?

开发者 https://www.devze.com 2023-03-10 02:25 出处:网络
Whew! First off, my apologies for the title, I don\'t speak English often. My question is, using an inline event registration, how can I pass the target element as an argument? Like this:

Whew! First off, my apologies for the title, I don't speak English often.

My question is, using an inline event registration, how can I pass the target element as an argument? Like this:

<element onClick='someEvent(thisElement)'></element>

What I have tried:

开发者_如何学Python
<element onClick='someEvent(this)'></element>

The code above is not working. Please help... Thank's in advance! I don't want to use addEventHandler 'coz the element will be created dynamically.


Looks fine to me

<script type="text/javascript">
function someEvent(t) {
    alert(t.tagName)
}
</script>

<a onclick='someEvent(this)'>Click me</a>

I think the cause of the problem is dynamic element generation. How are you adding the attribute to the element?

Why not just use addEventHandler during the dynamic element generation?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号