简体   繁体   中英

Dashcode - How do I get the name of a button from an event?

In Dashcode you can set up a handler for a behavior in the inspector.

Here's a sample handler for a button click on a button I've named "mybutton1" in the Inspector:

function myGetButtonName(event)
{
    var e = event.target;
    alert(e.id);
}

The problem is, when the button is clicked and the alert comes up it says the ID of the button is "DC_img1" rather than "myButton1" (which is what shows in the inspector in the id field).

I guess I'm not accessing the correct id.

Does anyone know how to get the id that shows in the attributes tab of the inspector?

Thanks!

OK, it turns out that the "id" that you may set on the attributes tab of the Dashcode Inspector is the CSS id of the element. I didn't realize that before.

To get that info I used this:

var x=event.currentTarget;
alert(x.id);

I don't know if it's the best way, but it gave me the correct result for each of the images that I was clicking on. I'm now getting the CSS id in the alert.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM