如何从动态表单输入中调用特定元素?

发布于 2024-11-27 19:18:28 字数 477 浏览 9 评论 0原文

我有一个表单输入,用于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诗酒趁年少 2024-12-04 19:18:28

您没有提供该列表的任何详细信息或您希望如何访问它,因此建议只能是一般性的。

如果您可以访问表单并且该控件有名称,则可以获取对表单控件的引用。如果名称是有效标识符:

var control = form.elements.elementName;

var control = form.elementName;

否则您可以使用:

var control = form.elements[elementName];

var control = form[elementName];

如果您有多个同名名称,则可以使用数字索引:

var control = form[elementName][index];

var control = form.elements[elementName][index];

如果您只知道是哪一个,则可以通过索引获取:

var control = form.elements[index];

或者

var control = form[index];

如果你想给一个元素一个 id(或更改其当前 ID),只需分配一个值:

element.id = 'whatever';

这些有帮助吗?

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:

var control = form.elements.elementName;

or

var control = form.elementName;

Otherwise you can use:

var control = form.elements[elementName];

or

var control = form[elementName];

If you have more than one with the same name, you can use a numeric index:

var control = form[elementName][index];

or

var control = form.elements[elementName][index];

Or if you just know which one it is, you can get it by index:

var control = form.elements[index];

or

var control = form[index];

If you want to give an element an id (or change its current ID), just assign a value:

element.id = 'whatever';

Does any of that help?

独享拥抱 2024-12-04 19:18:28

您可以使用以下语法定位特定行元素:

rows[i].object.templateElements.<NAME_OF_THE_ELEMENTS_CLASS>.style

其中 是您在 Dashcode GUI 中指定的名称(但保留 _template 附录),i 是特定行的索引(您在prepareRows 函数中获取索引) )。

示例:

rows[0].object.templateElements.text1.style

其中 text1 自动生成的 css 类名是 text1_template。

希望有帮助。

You can target a specific row element with the following syntax:

rows[i].object.templateElements.<NAME_OF_THE_ELEMENTS_CLASS>.style

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:

rows[0].object.templateElements.text1.style

where the automatic generated css classname for text1 is text1_template.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文