如何在 javascript 中枚举 asp.net HTML 元素属性

发布于 2024-09-30 07:21:45 字数 600 浏览 0 评论 0原文

为了使长篇故事尽可能短(如果您真的只想切入正题,请忽略本段):

我正在使用 CuteEditor 来编辑非常特定的控件页面。在页面查看器应用程序中,这些控件使用 HTML5 canvii 来执行各种时髦的动画操作,但在 CuteEditor 中(执行相同的操作并不实际),它们由 IMG 元素表示以实现可编辑性。这些控件有很多属性,这些属性都是从 SQL 数据库保存和加载的。不同类型的控件具有不同可能的属性类型,在 CuteEditor 中,这些属性存储为元素的属性(例如 PipColour="Green")。我为 CuteEditor IMG 编辑器对话框创建了一个自定义选项卡,当控件类型为更改后,将调用 SQL 数据库来获取所有可能的属性,以便可以用相关的输入控件填充对话框。

现在,追逐:

在 CuteEditor 中,自定义对话框选项卡使用带有 SyncToView() 和 SyncTo(element) javascript 方法的 .ascx 文件来获取和设置正在编辑的元素的属性,使用

element.<attributename>

“因为我不一定知道什么属性” element' 将具有或它们将被称为什么,有没有办法通过名称枚举它们?

To make a long story as short as possible (ignore this paragraph if you really just want to cut to the chase):

I'm using CuteEditor to edit very specific pages of controls. In the page viewer application these controls use HTML5 canvii to do all sorts of funky anim stuff, but in CuteEditor (where it's not practical to do the same thing) they are represented by IMG elements for editability. These controls have a bunch of properties, and this is all saved and loaded from an SQL database. Different types of control have different possible types of properties, and in CuteEditor these are stored as attributes of the element (such as PipColour="Green") I have created a custom tab for the CuteEditor IMG editor dialog, which when the control type is changed, an SQL database is called to get all the possible properties so the dialog can be populated with the relevant input controls.

Now, the chase:

In CuteEditor, custom dialog tabs use a .ascx file with SyncToView() and SyncTo(element) javascript methods to get and set the attributes of the element being edited, using

element.<attributename>

Since I don't necessarily know what attributes 'element' will have or what they will be called, is there a way to enumerate through them all by name?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

丢了幸福的猪 2024-10-07 07:21:45

您可以使用以下代码片段,它将为您提供获取属性的基本概念

var element = document.getElementById("someId");
var arr = [];

for (var i=0, attrs=element.attributes, l=attrs.length; i<l; i++){
 arr.push(attrs.item(i).nodeName);
 values.push(attr.nodeValue);
}

You can use the following code snippet, it will give you the basic idea of getting Attributes

var element = document.getElementById("someId");
var arr = [];

for (var i=0, attrs=element.attributes, l=attrs.length; i<l; i++){
 arr.push(attrs.item(i).nodeName);
 values.push(attr.nodeValue);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文