• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

how to get the object which user clicked

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as the title,
how to get the object which user clicked?

please show the code of javascript,thanks a lot

my solution is poor:
my javaScript code is as follows:

any solution else? thanks a lot
[ April 16, 2008: Message edited by: bingbin zhang ]
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try following code

<SCRIPT LANGUAGE="JavaScript">


function doSomething(e) {

var targ;
if(!e) var e = window.event;

if (e.target) targ = e.target;

else if (e.srcElement) targ = e.srcElement;

if (targ.nodeType == 3) // defeat Safari bug
targ = targ.parentNode;
alert(targ.id?targ.id:targ.name);
}


Document onclik = doSomething;


</SCRIPT>
 
bingbin zhang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you very much!
i will try it as soon as i get home~~
would you like you explain it for me?
what does 'e' mean?and what do the attributes of 'e' mean?
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
e is an instance of Event. In real browsers, it's passed to the event listeners. In IE, it's tacked onto the window instance.
 
Bear Bibeault
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The properties of the Event instance also depend upon browser. Standards-compliant browsers follow the W3C layout of this object -- IE made up its own layout.

Because of such difference in how real browsers and IE handle events, if you are going to be doing event handling in your pages, it's best to adopt a JavaScript library that normalizes these differences on your behalf. Otherwise, you end up writing one set of code for IE, and one for standards-compliant browsers. Both the Prototype and jQuery libraries do this for you.
[ April 16, 2008: Message edited by: Bear Bibeault ]
 
bingbin zhang
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the problem is soluted.thanks a lot~~
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic