开发者

Pass an onclick event the id of the calling object

开发者 https://www.devze.com 2023-03-09 03:49 出处:网络
I\'m having to work within an environment in which I cannot use additional frameworks. I am trying to send the id of a dynamically generated td to a function to be processed.

I'm having to work within an environment in which I cannot use additional frameworks.

I am trying to send the id of a dynamically generated td to a function to be processed.

Looks something like this:

'<td id="td' +开发者_运维知识库 j + '" class="r' + i + 'c' + j%2 + '" onclick=GetLocation(this)>'

I'm just not sure (and cannot find after reading articles for an hour or so) how to pass the object's id. Any insight would be appreciated.


My guess is you could do the following in your GetLocation() function:

var GetLocation = function(someObject){
   var objectID = someObject.id;
   alert("the id is -> " + objectID);
};


If the id is assigned, you could either pass it as this.id or just pass this itself and access the id inside the function body like obj.id

0

精彩评论

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