Dashcode - 如何从事件中获取按钮的名称?
在 Dashcode 中,您可以为检查器中的行为设置处理程序。
下面是一个示例处理程序,用于单击我在检查器中命名为“mybutton1”的按钮:
function myGetButtonName(event)
{
var e = event.target;
alert(e.id);
}
问题是,当单击该按钮并且出现警报时,它会显示该按钮的 ID 是“DC_img1”而不是“ myButton1”(这是检查器中 id 字段中显示的内容)。
我想我没有访问正确的 id。
有谁知道如何获取检查器属性选项卡中显示的 id?
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,事实证明,您可以在 Dashcode Inspector 的属性选项卡上设置的“id”是该元素的 CSS id。我之前没有意识到这一点。
为了获取该信息,我使用了以下方法:
我不知道这是否是最好的方法,但它为我单击的每个图像提供了正确的结果。我现在在警报中获取 CSS id。
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:
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.