I开发者_Python百科've got a few DOM elements, say text-field input A, B, C, and all of them have the property of 'onclick'. How do I find to which object a particular 'onclick' belongs?
You're probably trying to find the element that triggered an event handler.
If so, use the this
keyword.
EDIT
Apparently, you have an inline event handler as a string, and you're trying to find the element that the handler was attached to, from the string.
This is completely impossible.
A string is just a string. Just because your string happens to contain Javascript code, and happens to be assigned to a property on an object, doesn't make it any different from any other string; Javascript does not track parent references in objects.
Instead, you should bind an anonymous function as an event handler using jQuery.
(Or, if you really don't want to use jQuery, addEventListener
/ attachEvent
)
精彩评论