Can I add a custom attribute to an HTML tag?

后端 未结 17 2633
醉话见心
醉话见心 2020-11-22 08:06

Can I add a custom attribute to an HTML tag like the following?


17条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 08:35

    I can think of a handy use for the custom tag "init". Include a JavaScript expression that gets evaluated at document.onLoad() time and provides a value for the tag, e.g.

    <p>The UTC date is <span init="new Date().toUTCString()">?</span>.<p>

    Some boilerplate JavaScript code would scan all the tags in the DOM at document.onload() time looking for the init attributes, evaluating the expressions that they contain, and assigning them to the containing tag's innerHTML. This would give HTML some of the power of JSP, PHP etc. Currently we have to split the HTML markup and the JavaScript code that illuminates it. Bugs love split code.

提交回复
热议问题