Best way to add metadata to HTML elements

前端 未结 6 2178
孤独总比滥情好
孤独总比滥情好 2021-02-07 04:35

I\'m trying to put together a way of marking up various components in HTML that get parsed by a jQuery script and created when the page loads.

For example, at the moment

相关标签:
6条回答
  • 2021-02-07 04:56

    Use xhtml with custom elements mixed in from another DTD. or use html5 with custom data- attributes

    0 讨论(0)
  • Go ahead and use an attribute for this, but use a data- prefix on it. Attributes with the prefix data- are explicitly allowed on all elements as of HTML5. Example:

    <a href="#" class="Theme-Button" data-theme="{style: 'win2007', icon: 'left', align:'center', fullWidth: true}"></a>
    

    It works today in all browsers, and because it's now specified behavior, it's future-proofed.

    0 讨论(0)
  • 2021-02-07 04:59

    Look at the jQuery .data() function.

    0 讨论(0)
  • 2021-02-07 05:03

    Use jquery's ".data" property. This is very handy and many people don't know about it.

    See this link for more information.

    0 讨论(0)
  • 2021-02-07 05:03

    One could also use classes for this sort of thing.

    <a href="#" class="Theme-Button Style-win2007 Icon-left Align-Center FullWidth"></a>
    

    You will have to pre define a lot of classes, but it doesn't feel too much different than handling each key value pair that you have to create.

    0 讨论(0)
  • 2021-02-07 05:09

    The Prototype library supports:

    element.store("key","value")

    and

    element.retrieve("key","value").

    Simple. Nice. Effective.

    0 讨论(0)
提交回复
热议问题