如何从动态表单输入中调用特定元素?
我有一个表单输入,用于 dashcode 中的列表。我正在尝试从列表中指定特定项目,以便可以使用下面的代码,但我不知道如何操作。
function fadeout(event)
{
// Values you provide
var itemToFadeOut = document.getElementById("text2"); // replace with name of element to fade
// Fading code
var fadeHandler = function(a, c, s, f){ itemToFadeOut.style.opacity = c; };
new AppleAnimator(8500, 13, 1.0, 0.0, fadeHandler).start();}
当我运行这个时,它说 itemToFadeOut 为 null,我理解这是因为该元素没有 Id,它只是一个类。如何从动态列表中获取特定元素的 ID?
I have a form input that I am using for a list in dashcode. I'm trying to specify a specific item from my list so I can use the code below, but I don't know how.
function fadeout(event)
{
// Values you provide
var itemToFadeOut = document.getElementById("text2"); // replace with name of element to fade
// Fading code
var fadeHandler = function(a, c, s, f){ itemToFadeOut.style.opacity = c; };
new AppleAnimator(8500, 13, 1.0, 0.0, fadeHandler).start();}
When I run this it says the itemToFadeOut is null which I understand because the element doesn't have an Id, it is just a class. How do I a specific element from my dynamic list an id?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有提供该列表的任何详细信息或您希望如何访问它,因此建议只能是一般性的。
如果您可以访问表单并且该控件有名称,则可以获取对表单控件的引用。如果名称是有效标识符:
或
否则您可以使用:
或
如果您有多个同名名称,则可以使用数字索引:
或
如果您只知道是哪一个,则可以通过索引获取:
或者
如果你想给一个元素一个 id(或更改其当前 ID),只需分配一个值:
这些有帮助吗?
You don't provide any details of the list or how you expect to access it, so advice can only be general.
You can get a reference to a form control if you can get to the form and the control has a name. If the name is a valid identifier:
or
Otherwise you can use:
or
If you have more than one with the same name, you can use a numeric index:
or
Or if you just know which one it is, you can get it by index:
or
If you want to give an element an id (or change its current ID), just assign a value:
Does any of that help?
您可以使用以下语法定位特定行元素:
其中 是您在 Dashcode GUI 中指定的名称(但保留 _template 附录),i 是特定行的索引(您在prepareRows 函数中获取索引) )。
示例:
其中 text1 自动生成的 css 类名是 text1_template。
希望有帮助。
You can target a specific row element with the following syntax:
where is the name that you gave it in the Dashcode GUI (but leave the _template appendix away) and i is the index of the specific row (you get the index in the prepareRows Function).
Example:
where the automatic generated css classname for text1 is text1_template.
Hope it helps.