<tfoot id='AsNPn'></tfoot>
<i id='AsNPn'><tr id='AsNPn'><dt id='AsNPn'><q id='AsNPn'><span id='AsNPn'><b id='AsNPn'><form id='AsNPn'><ins id='AsNPn'></ins><ul id='AsNPn'></ul><sub id='AsNPn'></sub></form><legend id='AsNPn'></legend><bdo id='AsNPn'><pre id='AsNPn'><center id='AsNPn'></center></pre></bdo></b><th id='AsNPn'></th></span></q></dt></tr></i><div id='AsNPn'><tfoot id='AsNPn'></tfoot><dl id='AsNPn'><fieldset id='AsNPn'></fieldset></dl></div>

    <small id='AsNPn'></small><noframes id='AsNPn'>

      <bdo id='AsNPn'></bdo><ul id='AsNPn'></ul>

      <legend id='AsNPn'><style id='AsNPn'><dir id='AsNPn'><q id='AsNPn'></q></dir></style></legend>

      在 JavaScript 的 HTML 标记中存储任意信息?

      时间:2023-07-31
        <tfoot id='YyMAL'></tfoot>
          <tbody id='YyMAL'></tbody>

        1. <i id='YyMAL'><tr id='YyMAL'><dt id='YyMAL'><q id='YyMAL'><span id='YyMAL'><b id='YyMAL'><form id='YyMAL'><ins id='YyMAL'></ins><ul id='YyMAL'></ul><sub id='YyMAL'></sub></form><legend id='YyMAL'></legend><bdo id='YyMAL'><pre id='YyMAL'><center id='YyMAL'></center></pre></bdo></b><th id='YyMAL'></th></span></q></dt></tr></i><div id='YyMAL'><tfoot id='YyMAL'></tfoot><dl id='YyMAL'><fieldset id='YyMAL'></fieldset></dl></div>

              <bdo id='YyMAL'></bdo><ul id='YyMAL'></ul>
              <legend id='YyMAL'><style id='YyMAL'><dir id='YyMAL'><q id='YyMAL'></q></dir></style></legend>
            • <small id='YyMAL'></small><noframes id='YyMAL'>

              1. 本文介绍了在 JavaScript 的 HTML 标记中存储任意信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                一个非常笼统的问题.

                我正在动态生成一个表单,该表单使用 HTML/JavaScript 拆分为多个级别的选项卡.

                I am dynamically generating a form that is split into multiple levels of tabs using HTML / JavaScript.

                我想使用 CSS 和 background-image 用星 * 符号突出显示一些字段(值与全局模板不同的字段).

                I want to highlight some of the fields (those that have a value differing from a global template) with a star * symbol using CSS and background-image.

                JS 字段遍历每个字段,比较其值,并在必要时为其设置 CSS 类.到目前为止,一切顺利.

                A JS field iterates through each field, compares its value, and sets a CSS class for it if necessary. So far, so good.

                现在,我不仅希望每个更改的字段都用星号标记,而且还希望它所在的选项卡.

                Now in addition, I want not only every changed field to be marked with a star, but also the tab it is in.

                因为我喜欢它简单,所以我想将选项卡的元素 ID 作为属性存储在每个字段的 HTML 标记中的某处(类似于parentTab").然后,JS 函数会突出显示该字段及其parentTab"元素(也可能是那个parentTab"元素).

                Because I love it simple, I would like to store the element ID of the tab as an attribute somewhere in each field's HTML tag (something like "parentTab"). The JS function then highlights the field and its "parentTab" element (and maybe that one's "parentTab" as well).

                我的第一种方法是滥用title"属性或其他东西来存储 parentTab.当然,这很脏.但是,如果我只是在 DIV 或 INPUT 标记中随意添加任意属性,它将不再有效,并且我觉得访问这些属性不太安全 - 谁知道不同的浏览器如何处理它,并且将来会处理它?

                My first approach is to misuse the "title" attribute or somethiong to store parentTab in. Of course, that's dirty. However, if I just wildly add arbitrary attributes to the DIV or INPUT tag, it won't validate any more and I feel less than secure accessing these attributes - who knows how different browsers handle it, and will handle it in the future?

                所以我的问题是:是否有一种有效的、符合标准的方式——某种属性——将任意数据存储在 HTML 标记中,以供 JavaScript 进一步处理?

                So my question is: Is there a valid, standards compliant way - an attribute of some sort - to store arbitrary data inside HTML tags, for further processing by JavaScript?

                当然,我可以创建一个parentTabs"JS 数组并完成它.但是将其存储在输入本身中会更加优雅.

                Of course, I could create a "parentTabs" JS array and be done with it. But storing it in the input itself would be so much more elegant.

                推荐答案

                您可以通过编写 isChildOf 函数来找出字段属于哪个选项卡式元素,如下所示:http://jimkeller.blogspot.com/2008/07/jquery-ischildof-is-element-child-of.html

                You could find out which tabbed element a field belongs to by writing an isChildOf function, like this: http://jimkeller.blogspot.com/2008/07/jquery-ischildof-is-element-child-of.html

                使用 DOM 来解决这个问题总是比以某种自定义格式复制数据更优雅".

                Using the DOM to work this out will always be more "elegant" than duplicating the data in some custom format.

                这篇关于在 JavaScript 的 HTML 标记中存储任意信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:计算所选文本 javascript/JQuery 的位置? 下一篇:为什么使用 HTML5 标签?

                相关文章

                  <bdo id='09LM4'></bdo><ul id='09LM4'></ul>

                  <legend id='09LM4'><style id='09LM4'><dir id='09LM4'><q id='09LM4'></q></dir></style></legend>
                  <tfoot id='09LM4'></tfoot>

                  <small id='09LM4'></small><noframes id='09LM4'>

                1. <i id='09LM4'><tr id='09LM4'><dt id='09LM4'><q id='09LM4'><span id='09LM4'><b id='09LM4'><form id='09LM4'><ins id='09LM4'></ins><ul id='09LM4'></ul><sub id='09LM4'></sub></form><legend id='09LM4'></legend><bdo id='09LM4'><pre id='09LM4'><center id='09LM4'></center></pre></bdo></b><th id='09LM4'></th></span></q></dt></tr></i><div id='09LM4'><tfoot id='09LM4'></tfoot><dl id='09LM4'><fieldset id='09LM4'></fieldset></dl></div>