简体   繁体   English

Dashcode - 如何从事件中获取按钮的名称?

[英]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. 在Dashcode中,您可以在检查器中为行为设置处理程序。

Here's a sample handler for a button click on a button I've named "mybutton1" in the Inspector: 这是一个按钮的示例处理程序,单击我在Inspector中命名为“mybutton1”的按钮:

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). 问题是,当单击按钮并且警报出现时,它表示按钮的ID是“DC_img1”而不是“myButton1”(这是在id字段的检查器中显示的)。

I guess I'm not accessing the correct id. 我想我没有访问正确的ID。

Does anyone know how to get the id that shows in the attributes tab of the inspector? 有谁知道如何获取检查器的属性选项卡中显示的ID?

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. 好的,事实证明,你可以在Dashcode Inspector的属性选项卡上设置的“id”是元素的CSS id。 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. 我现在正在警报中获取CSS ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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