Custom attributes - Yea or nay?

前端 未结 14 1917
南旧
南旧 2020-11-22 03:02

Recently I have been reading more and more about people using custom attributes in their HTML tags, mainly for the purpose of embedding some extra bits of data for use in ja

14条回答
  •  没有蜡笔的小新
    2020-11-22 03:30

    Spec: Create an ASP.NET TextBox control which dynamically auto-formats its text as a number, according to properties "DecimalSeparator" and "ThousandsSeparator", using JavaScript.


    One way to transfer these properties from the control to JavaScript is to have the control render out custom properties:

    
    

    Custom properties are easily accessible by JavaScript. And whilst a page using elements with custom properties won't validate, the rendering of that page won't be affected.


    I only use this approach when I want to associate simple types like strings and integers to HTML elements for use with JavaScript. If I want to make HTML elements easier to identify, I'll make use of the class and id properties.

提交回复
热议问题